BAT 文件:打开新的 cmd 窗口并在其中执行命令 [英] BAT file: Open new cmd window and execute a command in there

查看:60
本文介绍了BAT 文件:打开新的 cmd 窗口并在其中执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 BAT 文件中打开一个新的命令窗口:

I'm trying to open a new command window in a BAT file:

start %windir%system32cmd.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 server",这样我就不必打开新的 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屋!

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