来自 Bash Shell 的新应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2429763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:47:41  来源:igfitidea点击:

New Application Process from Bash Shell

bashunixshellprocessmingw

提问by Tom

I'm relearning UNIX commands to use git on windows using MINGW32.

我正在重新学习 UNIX 命令,以便在使用 MINGW32 的 Windows 上使用 git。

When I launch a program, for example "$ notepad hello.txt" I can't use the shell again until I close the notepad file or CTRL-C in the shell.

当我启动一个程序时,例如“$ notepad hello.txt”,在关闭记事本文件或外壳中的 CTRL-C 之前,我无法再次使用外壳。

How do I essentially fork a new process so I can use both programs?

我如何基本上分叉一个新进程,以便我可以使用这两个程序?

回答by Ignacio Vazquez-Abrams

Add a &to the end of the command:

&在命令末尾添加一个:

notepad hello.txt &

回答by JayM

Put an ampersand (&) at the end of the command line. That tells the shell to run the program in the background.

在命令行的末尾放置一个与号 (&)。这告诉 shell 在后台运行程序。

In UNIX, you can hit CTRL-z to suspend the currently running program (Instead of CTRL-c to kill it). Once it's suspended, you can use the 'bg' command to put it in the background. I don't think that will work on Windows, but you can try.

在 UNIX 中,您可以按 CTRL-z 挂起当前正在运行的程序(而不是按 CTRL-c 来终止它)。暂停后,您可以使用“bg”命令将其置于后台。我认为这不适用于 Windows,但您可以尝试。

回答by Daniel Haley

You can also create an alias in your .rc file so you don't have to add the ampersands each time.

您还可以在 .rc 文件中创建别名,这样您就不必每次都添加与号。

I had some trouble doing this in bash on Cygwin though.

不过,我在 Cygwin 上的 bash 中遇到了一些麻烦。

I ended up having to create a separate script file and add an alias to point to it.

我最终不得不创建一个单独的脚本文件并添加一个别名来指向它。

Script file contents (filename is "dtextpad"):

脚本文件内容(文件名为“dtextpad”):

#!/bin/bash.exe

C:/Program\ Files/TextPad\ 5/TextPad.exe $@ &

Alias in my .bashrc:

我的 .bashrc 中的别名:

alias tp='~/include/bin/dtextpad'

Now if I want to open a file in textpad, I can type tp filename

现在如果我想在 textpad 中打开一个文件,我可以输入 tp filename