Windows 批处理脚本启动程序和退出控制台

我有一个用于启动程序的批处理脚本,比如 notepad.exe。当我双击这个批处理文件时,记事本正常启动,但是启动 notepad.execmd的黑色窗口仍然在后台。为了启动 notepad.exe并使 cmd 窗口消失,我必须做什么?

Edit : 比使用 \I更复杂。

cmd调用 cygwin,而 cygwin启动 notepad

start \I \path\cygwin\bin\bash.exe

第一个窗口(cmd)消失,但是第二个窗口(cygwin bin bash.exe)仍然在后台。在 cygwin 脚本中,我使用 notepad.exe &,然后退出。

185557 次浏览

Use start notepad.exe.

More info with start /?.

%ComSpec% /c %systemroot%\notepad.exe

Hmm... i do it in one of my batch files like this, without using CALL or START :

%SystemRoot%\notepad.exe ..\%URI%
GOTO ENDF

I don't have Cygwin installed though and I am on Windows XP.

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.

%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 %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 "" "%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).

If you need to add parameters to the command, just append them quoted, i.e.:

start "" "%SystemRoot%\Notepad.exe" "<filename>"

The simplest way ist just to start it with start

start notepad.exe

Here you can find more information about start

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.

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

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)

what works with .bat

call BatToExecute