如何在Windows命令提示符下同时启动2个程序

问题描述 投票:0回答:7

我使用的是 Windows 7 64 位

这是我用来启动的代码片段

@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,但它指的是我正在使用的相同方法。

编辑:

使用启动命令,它只会启动 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
7个回答
25
投票

使用启动命令,它只会启动 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

4
投票

start 需要窗口标题参数。 尝试: 启动“Lolrecorder”“C:\Program Files (x86)\LOLReplay\LOLRecorder.exe” 启动“Lol-Launcher”“G:\League of Legends\lol.launcher.exe”

这将为通过启动启动的cmd窗口提供“Lolrecorder”和“Lol-Launcher”的标题


2
投票

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

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

这个参考到目前为止已经回答了几乎我曾经遇到过的有关 CMD 的每个问题。


1
投票

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


0
投票

有人闲逛可能有兴趣同时检查所有驱动器的正确性。这是一个简单的 .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)。


0
投票

这对我有用,使用 cmd 文件同时启动 2 个程序,无需

start

@echo off
"C:\Users\UserA\AppData\Local\Programs\OP.GG\OP.GG.exe" & "C:\Riot Games\Riot Client\RiotClientServices.exe" --launch-product=league_of_legends --launch-patchline=live
exit

“&”后面的命令无论如何都会被执行。

@echo off
programA.exe & programB.exe

只有“&&”之前的命令执行成功,才会执行“&&”之后的命令。

@echo off
programA.exe && programB.exe

0
投票

我使用了“|”,请注意,控制台中仅显示最后执行的输出:

@echo off
Program.exe 50279111 | Program.exe 50279222 | Program.exe 50279333

但在我的后端程序中,我可以看到所有三个同时连接。

© www.soinside.com 2019 - 2024. All rights reserved.