what does start/wait means in batch file - batch-file

In batch file, what does start/wait means
Example:
ECHO start/wait C:\\Example.exe
I am trying to run an exe, so what does start/wait indicates over here?

/wait forces the batch file to halt processing until the called program has finished executing.
(This can be useful, for example, if you are loading multiple items in your windows Startup folder, and the nature of the programs require that one be finished before the next starts loading. Put them all in a single batch file, using the /wait parameter, and only put a shortcut to the batch file in the Startup folder.) Command line parameters of the START command can be combined in a single line. Example:
START /max /wait NOTEPAD.EXE SOME.TXT
Source: http://aumha.org/a/batches.php

Related

Combine Windows CMD BAT files

I'm trying to build a .bat file that will run an executable Java SpringBoot web app jar file (keeping the cmd window open so that I can verify it started cleanly and close it/kill the process when I'm done), then wait 10 seconds to give the app time to start, then finally open it's URL in my web browser.
I've been able to get my intended functionality by breaking it down into two .bat files. The code I have below does what I want (except the echo message is repeated, but that's not a big deal).
I'd like to know how I can achieve the same functionality within a single .bat file.
I have launch.bat:
start wait.bat
java -jar C:\dev_tools\myapp.jar
which calls wait.bat:
echo Waiting for app to start before launching browser...
timeout 10
start http://localhost:8013/myapp/ && exit
Given the combined script is called launch.bat, put if not "%~1" == "" goto :JUMP on top, then the contents of launch.bat but with the first line changed to start launch.bat #, then place goto :EOF, then :JUMP, then the contents of wait.bat:
if not "%~1" == "" goto :JUMP
start launch.bat #
java -jar C:\dev_tools\myapp.jar
goto :EOF
:JUMP
echo Waiting for app to start before launching browser...
timeout 10
start http://localhost:8013/myapp/ && exit
When you now start launch.bat, it first checks if there is an argument, which should not be the case initially; so the first start command line is reached where the script executes itself, but with an argument (#) this time; the initially executed instance continues executing the rest until goto :EOF is reached, which terminates execution.
The recursively called instance will immediately continue execution at label :JUMP, where the code of the original wait.bat script is placed.
I think, this should work:
#echo off
start "MyApp" java.exe -jar C:\dev_tools\myapp.jar
echo Waiting for app to start before launching browser...
%SystemRoot%\System32\timeout.exe 10
start http://localhost:8013/myapp/
java.exe is started as separate process running parallel to cmd.exe instance processing this batch file.
So immediately after starting java.exe the information line is output by cmd.exe in initially opened console window.
Then timeout is executed to wait 10 seconds before finally the application is started with the HTTP URL.
Finally cmd.exe finishes processing the batch file as reading end of batch file which results in terminating the cmd.exe if started with option /C as done on double clicking on a batch file.
The Java application started as separate process keeps running independent on termination of cmd.exe processing the batch file.
I hope this is what you want.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
start /?
timeout /?

How run batch script to get output in text file

Below executable return string values in command but when i execute below batch script it pop up different command line console and exits hence i am not getting any values in output.txt
how to capture this result ?
c:\
cd C:\Windows\System32
start usbinvoke.exe argument >c:\result\outpput.txt
pause
usbinvoke.exe argument > C:\result\output.txt
Start starts programs in unusual ways. See start /?
See Command to run a .bat file
Your other commands are unnecessary.
You right click a shortcut to cmd and tick Run As Administrator on the compatibility tab
c:\
cd C:\Windows\System32
usbinvoke.exe argument >c:\result\output.txt
pause
start does not wait unless you use /wait argument. Suggest remove start and just run the executable.
You cannot redirect streams with a process that does not wait as the no handle is attached to the process.
If you require start then use arguments /b (same window) and /w (same as /wait).

Executing bat files one by one

What I got is a list of bat files:
file1.bat
file2.bat
…
file29.bat
I need them to run one after each other. Meaning when the file1.bat closes file2.bat starts and so on.
I tried this, but it doesn't work properly:
start /wait call file1.bat
start /wait call file2.bat
You might want to add more to your question to make it easier to understand. My guess is that you want the bat file to open the next one then close itself after that.
If that's what you want to do; add these commands to each of the files:
start file2.bat
exit
Of course, you'll want to change start file2.bat to start file3.bat and so on for each file.
If you want file1.bat to manage all of the files, I don't think that's possible in batch.
You didn't describe how exactly it's not doing what you expected. I'm guessing that what happens is you're having to shut down each script before the next one will continue.
Documentation on start says:
WAIT Start application and wait for it to terminate.
command/program
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.
If you must use start then you could force it to use the /c switch which will automatically close the window once it's done:
start /wait cmd /c call file1.bat
I'm not really sure you accomplish anything by using call so that ought to be equivalent to just:
start /wait cmd /c file1.bat
Using start creates a new window for each program and you may just want to have it all run in a single command processor window.
As noted by Biffin you can just list them all out in a master script and they will run in order.
call file1.bat
call file2.bat
...
call file29.bat
And a shorthand for that is:
for /l %%f in (1; 1; 29) do call file%%f.bat
Remember to double up those percent characters inside a batch script but not on the command line.
This question might explain some of the unexpected behavior you were seeing.
How to run multiple .BAT files within a .BAT file

Batch File not kicking off another batch file

I have created a batch(batA) file that kicks off another batch(marathon.bat) file. When I save batA onto my desktop and use
start /wait ..\marathon\marathon.bat -batch "C:\stuff"
it works just fine. However, when I save marathon.bat to my program files, which now has spaces in the name, and then use
start /wait c:\"Program Files (x86)\marathon\marathon.bat" -batch "c:\stuff"
I get the error:
'c:\Program' is not recognized as an internal or external command, operable program or batch file.
I know that you have to use double quotes so that it takes the spaces into consideration, but why is it stopping at c:\Program? I've tried moving the quotes around to different locations, but I can't seem to get it to recognize the second file.
Does this work for you?
start "" /wait %comspec% /c "c:\Program Files (x86)\marathon\marathon.bat" -batch "c:\stuff"
You have 2 problems with how you call your batch file.
First, you have placed your quotes at the wrong place. Instead of
start /wait c:\"Program Files (x86)\marathon\marathon.bat"
You should enclose your whole command with quotes, not only from the Program Files folder name:
start /wait "c:\Program Files (x86)\marathon\marathon.bat"
The second problem is that the first parameter with quotes specified to the START command is treated as the title of the new window. You should add an empty set of quotes before your command to circumvent this:
start "" /wait "c:\Program Files (x86)\marathon\marathon.bat"

DOS batch file to run 4 blocks of 3 parallel programs

The program is a FORTAN number-crunching code :: "C:\fct1d_intel_2\debug\fct1d_intel_2.exe"
This is called using the batch file "RUN.bat":
C:\fct1d_intel_2\debug\fct1d_intel_2.exe
exit
The following batch file "run_generator_3procs_1to3.bat" kicks-off the 3 parallel programs in separate directories:
CD C:\FCT_Polystyrene_Model_Calibration\Proc_01
start /min run.bat
CD C:\FCT_Polystyrene_Model_Calibration\Proc_02
start /min run.bat
CD C:\FCT_Polystyrene_Model_Calibration\Proc_03
start /min run.bat
The following batch file "run_12_cases_4X3.bat" calls 4 sequential versions of of the preceding batchfile:
call run_generator_3procs_7to9.bat
call run_generator_3procs_10to12.bat
call run_generator_3procs_1to3.bat
call run_generator_3procs_4to6.bat
Now the first call "run_generator_3procs_7to9.bat" runs the 3 parallel programs fine but does not move on to the next 3 batch files.
Could anyone please advise me on what I am doing wrong.
Check that you are not trying to access files at the same time with different batch files. It might be executing, but just closing as they fail to run.

Resources