问题
I am using Windows 7 64bit
Here is the code snippet I am using to start
@echo off
call "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
call "G:\League of Legends\lol.launcher.exe"
exit
But unless I close LOLRecorder.exe it won't start my lol.launcher.exe.... basically I want both running and the cmd prompt exit after they start. Whats wrong here? I checked out another stackoverflow answer Here but it refers to the same method I am using.
EDIT:
With the start command it just starts 2 terminal windows and nothing starts!
@echo off
start "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
start "G:\League of Legends\lol.launcher.exe"
exit
回答1:
With the start command it just starts 2 terminal windows and nothing starts!
The problem is the quotes (which are unfortunately required, due to the spaces in the paths). The start
command doesn't seem to like them.
You can work around this by using the short DOS names for all the directories (and remove quotes), or by specifying the directory separately and quoting it (which the start
command seems to be able to deal with).
Try this:
@echo off
start /d "C:\Program Files (x86)\LOLReplay" LOLRecorder.exe
start /d "G:\League of Legends" lol.launcher.exe
Or, if your batch files become more complicated in the future, or your program names have spaces in them, this:
@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
回答2:
start requires parameters for window title. Try: start "Lolrecorder" "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe" start "Lol-Launcher" "G:\League of Legends\lol.launcher.exe"
This will give the cmd-windows started by start the title of "Lolrecorder" and "Lol-Launcher"
回答3:
Specify a title and the /c switch to tell the STARTed window to go away after its command finishes.
start "recorder" /c "C:\Program Files (x86)\LOLReplay\LOLRecorder.exe"
start "LOL" /c "G:\League of Legends\lol.launcher.exe"
This reference has so far answered almost every question I've ever had about CMD.
回答4:
call
is for batch files only, and it waits for the callee to return. You should use the start
command to start programs backgrounded. As an added bonus you can specify a priority for the process. If you need to run something as another user, use runas
.
回答5:
Someone wandering may be interested in checking correctness of all drives in the same time. Here is a simple .bat file for that:
@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"
Script waits for key after checking each drive. Each drive has its own cmd window.
You should avoid checking and fixing (above is only checking) drives, where one drive is a container in another (eg. VeraCrypt container, VHD, VHDX).
来源:https://stackoverflow.com/questions/6487766/how-to-start-2-programs-simultaneously-in-windows-command-prompt