Windows批处理脚本程序启动和退出控制台 [英] Windows batch script launch program and exit console

查看:727
本文介绍了Windows批处理脚本程序启动和退出控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我用来启动一个程序,如的notepad.exe 批处理脚本。当我双击此批处理文件,记事本可以正常启动,但黑色窗口中的 CMD 谁发动的notepad.exe 保持在背景中。我有什么才能发动做的notepad.exe 并做出cmd窗口消失?

修改:是不是使用 \\ I

更复杂。

CMD 要求的cygwin 的cygwin 启动记事本。我用

启动\\ I \\路径\\ cygwin的\\斌\\ bash.exe

和第一窗口(CMD)消失,但第二窗口(\\ cygwin的\\仓\\ bash.exe)仍然在背景。在cygwin剧本我用的notepad.exe和放大器; ,然后退出


解决方案

 启动的%SystemRoot%\\ Notepad.exe的

请在在开始和你的应用程序路径之间。


补充说明:

通常情况下,当我们从象下面的批处理文件启动一个程序,我们将有黑色的窗户像OP后台说。

 的%SystemRoot%\\ Notepad.exe的

这是原因通过记事本在同一命令提示符(进程)运行。命令提示符将关闭记事本后关闭。为了避免这种情况,我们可以使用启动命令来启动这样一个单独的进程。

 启动的%SystemRoot%\\ Notepad.exe的

此命令罚款,只要它不具有在路径空间。为了处理路径中的空间,以防万一,我们增加了报价是这样的。

 启动的%SystemRoot%\\ Notepad.exe的

但在运行此命令将刚刚起步的又一空白命令提示符。为什么?如果查找到启动/?启动命令将识别的参数中的 ,因为它是要推出新的命令提示符的标题所以,要解决这个问题,我们有命令是这样的:

 启动的%SystemRoot%\\ Notepad.exe的

的第一个参数是设置标题(我们设置为空白),和第二个参数
的%SystemRoot%\\ Notepad.exe的是目标命令来运行(在路径支撑位)。

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?

edit: is more complicated than using \I.

The cmd calls cygwin, and cygwin starts notepad. I use

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.

解决方案

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

这篇关于Windows批处理脚本程序启动和退出控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆