如何在CMD中使用start命令启动多个程序

3

在CMD中,是否可以让start命令在新线程上运行多个命令? 我尝试了以下方法:

:: Use start to finish before we're deleted
start /min (
    :: Do some work...
    :: Remove the app's root folder
    rd /s /q %~dp0
)

但是我得到了"Windows无法找到文件)。确保您正确键入名称,然后重试。"的错误提示。

有没有不需要创建新批处理脚本的方法来解决这个问题?

1个回答

7
使用cmd /c "........"命令,并使用&分隔多个命令。
  • start a new minimized console window

    start /min "window title" cmd /c "action1 & action2 >logfile.txt & action3"
    

    When omitting the outer quotes make sure to escape the special characters like <, >, &, |:

    start /min "" cmd /c action1 ^& action2 "some parameter" ^>"logfile.txt" ^& action3
    

    When using the outer quotes repeat the inner quotes three times:

    start /min "" cmd /c "action1 & action2 >"""some logfile.txt""" & action3"
    
  • start a new process in the current console window:

    start /b "" cmd /c ......
    
  • an example of multiline syntax for improved readability:

    start /min "" cmd /c ^
        dir r:\ %= inline comment =% ^& ^
        echo 2 ^>r:\2 ^& ^
        %= inline comment =% ^
        pause
    

其中最丑陋的之一,没错。 - wOxxOm
你应该能够将所有的命令放在一行上,并用引号将它们全部括起来。 - Squashman
确实很有用。我已经添加了示例。 - wOxxOm
@wOxxOm - 在最后一个代码示例中,这是否意味着必须存在一个可执行文件用于 r:\2,例如 2.exe2.bat - lit
@Liturgist,echo的输出被重定向到文件r:\2 - wOxxOm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接