Windows 批处理脚本启动程序并退出控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5909012/
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
Windows batch script launch program and exit console
提问by Possa
I have a batch script that I use to launch a program, such as notepad.exe
. When I double click on this batch file, notepad starts normally, but the black window of the cmd
who launched notepad.exe
remains in the background. What do I have to do in order to launch notepad.exe
and make the cmd window disappear?
我有一个用于启动程序的批处理脚本,例如notepad.exe
. 当我双击这个批处理文件,记事本可以正常启动,但附近的黑色窗口cmd
是谁发动notepad.exe
仍在后台。我该怎么做才能启动notepad.exe
并使 cmd 窗口消失?
edit: is more complicated than using \I
.
编辑:比使用更复杂\I
。
The cmd
calls cygwin
, and cygwin
starts notepad
. I use
该cmd
电话cygwin
,和cygwin
开始notepad
。我用
start \I \path\cygwin\bin\bash.exe
start \I \path\cygwin\bin\bash.exe
and the first window (cmd) disappears, but a second window (\cygwin\bin\bash.exe) is still on the background. In the cygwin script I used notepad.exe &
and then exit.
第一个窗口 (cmd) 消失了,但第二个窗口 (\cygwin\bin\bash.exe) 仍在后台。在我使用的 cygwin 脚本中notepad.exe &
,然后退出。
回答by checksum
start "" "%SystemRoot%\Notepad.exe"
Keep the ""
in between start and your application path.
保持""
在开始和您的应用程序路径之间。
Added explanation:
补充说明:
Normally when we launch a program from a batch file like below, we'll have the black windows at the background like OP said.
通常,当我们从如下所示的批处理文件启动程序时,我们会像 OP 所说的那样在后台显示黑色窗口。
%SystemRoot%\Notepad.exe
This was cause by Notepad running in same command prompt (process). The command prompt will close AFTER notepad is closed. To avoid that, we can use the start
command to start a separate process like this.
这是由在同一命令提示符(进程)中运行的记事本引起的。命令提示符将在记事本关闭后关闭。为了避免这种情况,我们可以使用该start
命令来启动这样一个单独的进程。
start %SystemRoot%\Notepad.exe
This command is fine as long it doesn't has space in the path. To handle space in the path for just in case, we added the "
quotes like this.
只要路径中没有空格,此命令就可以。为了以防万一,处理路径中的空间,我们添加了"
这样的引号。
start "%SystemRoot%\Notepad.exe"
However running this command would just start another blank command prompt. Why? If you lookup to the start /?
, the start
command will recognize the argument between the "
as the title of the new command prompt it is going to launch. So, to solve that, we have the command like this:
但是,运行此命令只会启动另一个空白命令提示符。为什么?如果您查找start /?
,该start
命令会将 之间的参数识别"
为它将要启动的新命令提示符的标题。所以,为了解决这个问题,我们有这样的命令:
start "" "%SystemRoot%\Notepad.exe"
The first argument of ""
is to set the title (which we set as blank), and the second argument of
"%SystemRoot%\Notepad.exe"
is the target command to run (that support spaces in the path).
第一个参数""
是设置标题(我们设置为空白),第二个参数
"%SystemRoot%\Notepad.exe"
是要运行的目标命令(支持路径中的空格)。
If you need to add parameters to the command, just append them quoted, i.e.:
如果需要在命令中添加参数,只需将它们加上引号即可,即:
start "" "%SystemRoot%\Notepad.exe" "<filename>"
回答by Benoit
Use start notepad.exe
.
使用start notepad.exe
.
More info with start /?
.
更多信息与start /?
。
回答by MrBogus
%ComSpec% /c %systemroot%\notepad.exe
%ComSpec% /c %systemroot%\notepad.exe
回答by brothers28
回答by djangofan
Hmm... i do it in one of my batch files like this, without using CALL or START :
嗯...我在这样的批处理文件之一中执行此操作,而不使用 CALL 或 START :
%SystemRoot%\notepad.exe ..\%URI%
GOTO ENDF
I don't have Cygwin installed though and I am on Windows XP.
虽然我没有安装 Cygwin,但我使用的是 Windows XP。
回答by Tomasz Janicki
start "" ExeToExecute
method does not work for me in the case of Xilinx xsdk, because as pointed out by @jeb in the comments below it is actaully a bat file.
在 Xilinx xsdk 的情况下,该方法对我不起作用,因为正如@jeb 在下面的评论中指出的那样,它实际上是一个 bat 文件。
so what does not work de-facto is
所以实际上不起作用的是
start "" BatToExecute
I am trying to open xsdk like that and it opens a separate cmd that needs to be closed and xsdk can run on its own
我正在尝试像这样打开 xsdk,它会打开一个需要关闭的单独 cmd,并且 xsdk 可以自行运行
Before launching xsdk I run (source) the Env / Paths (with settings64.bat) so that xsdk.bat command gets recognized (simply as xsdk, withoitu the .bat)
在启动 xsdk 之前,我运行(源)Env / Paths(带有settings64.bat)以便 xsdk.bat 命令被识别(简单地作为 xsdk,没有.bat)
what works with .bat
什么适用于.bat
call BatToExecute
回答by yyyx
Try to start path\to\cygwin\bin\bash.exe
尝试开始 path\to\cygwin\bin\bash.exe