For exe files, I suppose the differences are nearly unimportant.
But to start an exe you don't even need CALL
.
When starting another batch it's a big difference,
as CALL
will start it in the same window and the called batch has access to the same variable context.
So it can also change variables which affects the caller.
START
will create a new cmd.exe for the called batch and without /b it will open a new window.
As it's a new context, variables can't be shared.
Using start /wait <prog>
- Changes of environment variables are lost when the <prog>
ends
- The caller waits until the <prog>
is finished
Using call <prog>
- For exe it can be ommited, because it's equal to just starting <prog>
- For an exe-prog the caller batch waits or starts the exe asynchronous, but the behaviour depends on the exe itself.
- For batch files, the caller batch continues, when the called <batch-file>
finishes, WITHOUT call the control will not return to the caller batch
Using CALL
can change the parameters (for batch and exe files), but only when they contain carets or percent signs.
call myProg param1 param^^2 "param^3" %%path%%
Will be expanded to (from within an batch file)
myProg param1 param2 param^^3 <content of path>
I think that they should perform generally the same, but there are some differences.
START
is generally used to start applications or to start the default application for a given file type. That way if you START http://mywebsite.com
it doesn't do START iexplore.exe http://mywebsite.com
.
START myworddoc.docx
would start Microsoft Word and open myworddoc.docx.CALL myworddoc.docx
does the same thing... however START
provides more options for the window state and things of that nature. It also allows process priority and affinity to be set.
In short, given the additional options provided by start, it should be your tool of choice.
START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
[command/program] [parameters]
"title" Title to display in window title bar.
path Starting directory.
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
I The new environment will be the original environment passed
to the cmd.exe and not the current environment.
MIN Start window minimized.
MAX Start window maximized.
SEPARATE Start 16-bit Windows program in separate memory space.
SHARED Start 16-bit Windows program in shared memory space.
LOW Start application in the IDLE priority class.
NORMAL Start application in the NORMAL priority class.
HIGH Start application in the HIGH priority class.
REALTIME Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.
NODE Specifies the preferred Non-Uniform Memory Architecture (NUMA)
node as a decimal integer.
AFFINITY Specifies the processor affinity mask as a hexadecimal number.
The process is restricted to running on these processors.
The affinity mask is interpreted differently when /AFFINITY and
/NODE are combined. Specify the affinity mask as if the NUMA
node's processor mask is right shifted to begin at bit zero.
The process is restricted to running on those processors in
common between the specified affinity mask and the NUMA node.
If no processors are in common, the process is restricted to
running on the specified NUMA node.
WAIT Start application and wait for it to terminate.
There is a useful difference between call
and start /wait
when calling regsvr32.exe /s
for example, also referenced by Gary in
in his answer to how-do-i-get-the-application-exit-code-from-a-windows-command-line
call regsvr32.exe /s broken.dll
echo %errorlevel%
will always return 0 but
start /wait regsvr32.exe /s broken.dll
echo %errorlevel%
will return the error level from regsvr32.exe
This is what I found while running batch files in parallel (multiple instances of the same bat file at the same time with different input parameters) :
Lets say that you have an exe file that performs a long task called LongRunningTask.exe
If you call the exe directly from the bat file, only the first call to the LongRunningTask will succed, while the rest will get an OS error "File is already in use by the process"
If you use this command:
start /B /WAIT "" "LongRunningTask.exe" "parameters"
You will be able to run multiple instances of the bat and exe, while still waiting for the task to finish before the bat continues executing the remaining commands. The /B option is to avoid creating another window, the empty quotes are needed in order to the command to work, see the reference below.
Note that if you don´t use the /WAIT in the start, the LongRunningTask will be executed at the same time than the remaining commands in the batch file, so it might create problems if one of these commands requires the output of the LongRunningTask
Resuming :
This can´t run in parallel :
This will run in parallel and will be ok as far as there are no data dependencies between the output of the command and the rest of the bat file :
This will run in parallel and wait for the task to finish, so you can use the output :
Reference for the start command : How can I run a program from a batch file without leaving the console open after the program start?
Call
Calls one batch program from another without stopping the parent batch program. The call command accepts labels as the target of the call. Call has no effect at the command-line when used outside of a script or batch file. https://technet.microsoft.com/en-us/library/bb490873.aspx
Start
Starts a separate Command Prompt window to run a specified program or command. Used without parameters, start opens a second command prompt window. https://technet.microsoft.com/en-us/library/bb491005.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With