187

How is the START command with a WAIT option

START /wait notepad.exe START /wait  notepad.exe

...any different from using a CALL command?

CALL notepad.exe CALL notepad.exe

Is there a situation where one may behave differently that the other dependending on what is being executed?

askedNov 6, 2012 at 19:00
Chad's user avatar
1

5 Answers5

238

Forexe files, I suppose the differences are nearly unimportant.
But to start anexe you don't even needCALL.

When starting another batch it's a big difference,
asCALL 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.

Differences

Usingstart /wait <prog>
- Changes of environment variables are lost when the<prog> ends
- The caller waits until the<prog> is finished

Usingcall <prog>
- Forexe it can be ommited, because it's equal to just starting<prog>
- For anexe-prog the caller batch waits or starts theexe asynchronous, but the behaviour depends on theexe itself.
- Forbatch files, the caller batch continues, when the called<batch-file> finishes, WITHOUT call the control will not return to the caller batch

Addendum:

UsingCALL 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>
answeredNov 6, 2012 at 19:59
jeb's user avatar
Sign up to request clarification or add additional context in comments.

8 Comments

When executing a file.bat using START /WAIT you need to specify START /WAIT cmd /c "file.bat" rather than just START /WAIT "file.bat", else the cmd window created for file.bat will remain open
You can find the comparison between CALL and START at:ss64.com/nt/start.html (updated today with sections "Start /Wait" and "START vs CALL")
My favourite isstart /wait /b cmd /c <batchfile.bat> because the batch files run one after the other in the same command window
@linux64kb, But for batch files it's not necessary, you only needcall batchfile.bat
Doesn't "setlocal" do that for you?
|
22

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 youSTART http://mywebsite.com it doesn't doSTART iexplore.exe http://mywebsite.com.

START myworddoc.docx would start Microsoft Word and open myworddoc.docx.CALL myworddoc.docx does the same thing... howeverSTART 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.
answeredNov 6, 2012 at 20:06
gudatcomputers's user avatar

Comments

14

There is a useful difference betweencall andstart /wait when callingregsvr32.exe /s for example, also referenced byGaryin in his answer tohow-do-i-get-the-application-exit-code-from-a-windows-command-line

call regsvr32.exe /s broken.dllecho %errorlevel%

will always return 0 but

start /wait regsvr32.exe /s broken.dllecho %errorlevel%

will return the error level from regsvr32.exe

answeredDec 18, 2014 at 11:45
aedjp's user avatar

Comments

10

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 :

  • call LongRunningTask.exe

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 :

  • start /B "" "LongRunningTask.exe" "parameters"

This will run in parallel and wait for the task to finish, so you can use the output :

  • start /B /WAIT "" "LongRunningTask.exe" "parameters"

Reference for the start command :How can I run a program from a batch file without leaving the console open after the program start?

answeredMay 17, 2017 at 18:17
Cherno's user avatar

Comments

9

Call

Calls one batch program from anotherwithout 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 aseparate 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

answeredJun 17, 2016 at 12:21
NoWar's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.