How to use the start command in a batch file? - windows-7

I have a batch file that starts an app with a lot of command-line parameters:
"C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
The problem is that when I run the batch file, the DOS window stays up until the command completes and I would like it to go away. So I tried using the start command, but placing it in front, like this:
start "C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
But I get an error stating that Invalid switch - "/port:1672"
I have also tried escaping the double quotes, but I was not successful.
How do I fix that?

An extra pair of rabbits' ears should do the trick.
start "" "C:\Program...
START regards the first quoted parameter as the window-title, unless it's the only parameter - and any switches up until the executable name are regarded as START switches.

I think this other Stack Overflow answer would solve your problem: How do I run a bat file in the background from another bat file?
Basically, you use the /B and /C options:
START /B CMD /C CALL "foo.bat" [args [...]] >NUL 2>&1

Related

How do I format the Target field of a Windows SendTo shortcut to quote the paths I'm passing to it?

OS: Windows 10
I have a Windows shortcut in my SendTo folder with the following Target:
C:\Windows\System32\cmd.exe /c "C:\Program Files\Path\To\Executable.exe"
This works just fine if I pass it a file or files without spaces in their filenames. But if I pass it files with spaces, I get the following error:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
(I changed it to /k to see the error. /c terminates right away, so I couldn't see the error message.)
If I launch it from inside a CMD session, I would do:
C:\Windows\System32\cmd.exe /c ""C:\Program Files\Path\To\Executable.exe" "path to/first" "path to/second""
But I'm not sure how to tell the Target field to do that. I tried:
C:\Windows\System32\cmd.exe /c ""C:\Program Files\Path\To\Executable.exe" "%1" "%2" "%3""
But that passed a literal %1 as the first argument, a literal %2 as the second argument, and then the file that I right-clicked and chose "Send To -> MyShortcut", prepended by a literal "%3 " as the third argument.
I need to be able to pass at most three arguments.
cmd.exe is stupid and will strip quotes if the command starts and ends with quotes.
Change the shortcuts command to C:\Windows\System32\cmd.exe /c if 1==1 "C:\Program Files\Path\To\Executable.exe"

Rest of script not running after calling a batch file to run?

I have the following script batch script:
call standalone.bat
"C:\Program Files (x86)\Notepad++\notepad++.exe" "C:\Program Files\jboss-eap-6.2\jboss-eap-6.2\standalone\log\server.log"
The first command runs as expected but the script never seems to call notepad to open the server.log file.
What is the issue here?
Edit: ending of standalone.bat is:
if ERRORLEVEL 10 goto RESTART
:END
if "x%NOPAUSE%" == "x" pause
:END_NO_PAUSE
Stephan likely diagnosed the problem in his question comment - standalone.bat probably terminates with an exit command. If that is correct, then you can work around the problem without modifying standalone.bat by changing
call standalone.bat
to
cmd /c standalone.bat.

startup batch file hangs up on second command

I created a startup bat file that looks like this
taskkill /im RemoteDesktopManager.exe
C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
"C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
"C:\Program Files\Mozilla Firefox\firefox.exe"
it does the first and second, but won't go any further, they all exist
how can I fix this?
update : I tried suggestion provided by #phd443322 and wrote this:
taskkill /im RemoteDesktopManager.exe
start "" /w C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" /w "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" /w "C:\Program Files\Mozilla Firefox\firefox.exe"
intrestingly each command still waits for that program to be closed to continue to the next.
so why still not working?
Below there is a working Batch file, as first advised by phd443322:
taskkill /im RemoteDesktopManager.exe
start "" C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
Batch files wait for programs to exit unlike interactive. These are the rules documented in the Start command.
If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:
non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.
When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.
When executing a command line whose first token is the string "CMD "
without an extension or path qualifier, then "CMD" is replaced with
the value of the COMSPEC variable. This prevents picking up CMD.EXE
from the current directory.
When executing a command line whose first token does NOT contain an
extension, then CMD.EXE uses the value of the PATHEXT
environment variable to determine which extensions to look for
and in what order. The default value for the PATHEXT variable
is:
.COM;.EXE;.BAT;.CMD
Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.
When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.

Running Several batch Commands in Sequence

When i run this batch file command as a single batch file the second command does not run.However when i run them as individual batch file commands they work fine.
"C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com/error.html
"nircmd.exe" win hide process "firefox.exe"
tried creating 1 single batch file which called with a call the two batch files now having separated the batch files command separately like this
call test.bat
call hide.bat
where test.bat contained the first command and hide.bat contained the second command but it still didnt work.What am i doing wrong?
It may be that firefox.exe never returns until you close the window. Try using start to launch the applications, as start will return as soon as the application has launched.
start "" "C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com/error.html
start "" "nircmd.exe" win hide process "firefox.exe"
The first command, "C:\Program Files\Mozilla Firefox\firefox.exe" does not return until the Fx session has ended (ie you EXIT from it)
Then there are no Fx executables so the second command can't hide the process that doesn't exist.
Try
START "" "C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com error.html
"nircmd.exe" win hide process "firefox.exe"
The only difference is the START "" before the firefox-invocation. Note that the empty-quoted-string is required - you could enter a string between the quotes if you like - this becomes the window title.

How to start 2 programs simultaneously in windows command prompt

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
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
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"
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.
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.
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).

Resources