【问题标题】:How to start 2 programs simultaneously in windows command prompt如何在 Windows 命令提示符下同时启动 2 个程序
【发布时间】:2011-09-23 04:26:54
【问题描述】:

我使用的是 Windows 7 64 位

这是我用来启动的代码 sn-p

@echo off
call "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
call "G:\League of Legends\lol.launcher.exe"
exit

但除非我关闭 LOLRecorder.exe,否则它不会启动我的 lol.launcher.exe.... 基本上我希望在它们启动后运行和 cmd 提示符退出。这里有什么问题?我查看了另一个 stackoverflow 答案 Here,但它指的是我正在使用的相同方法。

编辑:

使用 start 命令,它只会启动 2 个终端窗口,但什么也没有启动!

@echo off
start "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
start "G:\League of Legends\lol.launcher.exe"
exit

【问题讨论】:

    标签: windows-7 command-line cmd command-prompt windows-console


    【解决方案1】:

    call 仅用于批处理文件,它等待被调用者返回。您应该使用start 命令来启动后台程序。作为额外的奖励,您可以指定流程的优先级。如果您需要以其他用户身份运行某些内容,请使用 runas

    【讨论】:

    • @footy:这两个命令中的任何一个是否单独(没有start)正确启动相应的程序,或者您是否可能缺少一些基本的命令行选项? (哦,我认为不需要说“退出”。)
    • 单独工作。启动这些程序时,我无需提供任何 cmd 行参数。
    【解决方案2】:

    使用 start 命令,它只会启动 2 个终端窗口,但什么也没有启动!

    问题在于引号(不幸的是,由于路径中的空格,引号是必需的)。 start 命令似乎不喜欢它们。

    您可以通过对所有目录使用短 DOS 名称(并删除引号)来解决此问题,或者通过单独指定目录并引用它(start 命令似乎能够处理)。

    试试这个:

    @echo off
    start /d "C:\Program Files (x86)\LOLReplay" LOLRecorder.exe
    start /d "G:\League of Legends" lol.launcher.exe
    

    或者,如果您的批处理文件将来变得更加复杂,或者您的程序名称中有空格,则:

    @ECHO OFF
    
    CALL :MainScript
    GOTO :EOF
    
    :MainScript
      CALL :RunProgramAsync "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
      CALL :RunProgramAsync "G:\League of Legends\lol.launcher.exe"
    GOTO :EOF
    
    :RunProgramAsync
      REM ~sI expands the variable to contain short DOS names only
      start %~s1
    GOTO :EOF
    

    【讨论】:

      【解决方案3】:

      start 需要窗口标题的参数。 尝试: 启动 "Lolrecorder" "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe" 启动“Lol-Launcher”“G:\英雄联盟\lol.launcher.exe”

      这会给以“Lolrecorder”和“Lol-Launcher”为标题的cmd-windows启动

      【讨论】:

        【解决方案4】:

        指定标题和 /c 开关以告知已启动的窗口在其命令完成后消失。

        start "recorder" /c "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
        start "LOL" /c "G:\League of Legends\lol.launcher.exe"
        

        到目前为止,这个reference 回答了我几乎关于 CMD 的所有问题。

        【讨论】:

          【解决方案5】:

          徘徊的人可能有兴趣同时检查所有驱动器的正确性。这是一个简单的 .bat 文件:

          @echo off
          for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%a:\ start cmd /c "echo %%a: & chkdsk %%a: & pause"
          

          脚本在检查每个驱动器后等待密钥。每个驱动器都有自己的 cmd 窗口。

          您应该避免检查和修复(以上只是检查)驱动器,其中一个驱动器是另一个驱动器中的容器(例如 VeraCrypt 容器、VHD、VHDX)。

          【讨论】:

            猜你喜欢
            • 2013-06-28
            • 1970-01-01
            • 2014-09-03
            • 1970-01-01
            • 2016-01-23
            • 1970-01-01
            • 2020-06-13
            • 2016-05-16
            • 1970-01-01
            相关资源
            最近更新 更多