BAT文件:打开新的cmd窗口并在其中执行命令 [英] BAT file: Open new cmd window and execute a command in there
问题描述
我正在尝试在BAT文件中打开一个新的命令窗口:
I'm trying to open a new command window in a BAT file:
start %windir%\system32\cmd.exe
打开后,我想在新窗口中执行BAT命令:
After it opens, I'd like to execute a BAT command in the new window:
echo "test in new window"
我该怎么做?
推荐答案
您可能已经找到答案了,因为它是在不久前您提出的.但是我在编码ror时尝试做类似的事情.我想在新的cmd窗口中运行"rails服务器",所以不必打开新的cmd,然后再次找到路径.
You may already find your answer because it was some time ago you asked. But I tried to do something similar when coding ror. I wanted to run "rails server" in a new cmd window so I don't have to open a new cmd and then find my path again.
我发现是这样使用K开关的:
What I found out was to use the K switch like this:
start cmd /k echo Hello, World!
在"cmd"将在新窗口中打开应用程序之前启动,"/K"将执行"echo Hello,World!".新的cmd启动后.
start before "cmd" will open the application in a new window and "/K" will execute "echo Hello, World!" after the new cmd is up.
您也可以使用/C开关进行类似操作.
You can also use the /C switch for something similar.
start cmd /C pause
这将执行暂停",但在命令完成后关闭窗口.在这种情况下,您按下按钮后.我发现这对于"rails服务器"很有用,然后当我关闭开发服务器时,不必再关闭窗口.
This will then execute "pause" but close the window when the command is done. In this case after you pressed a button. I found this useful for "rails server", then when I shutdown my dev server I don't have to close the window after.
这篇关于BAT文件:打开新的cmd窗口并在其中执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!