Supposing there is a batch file (caller) which executes another batch file (callee), the call
command needs to be used in order to return to the caller after the callee finishes execution. Here is an example:
caller.bat
:
echo Calling another script...
call callee.bat
echo Returned from callee...
callee.bat
(in the same location):
echo Being called from caller...
The output will be this (omitting the command echos), showing that execution returned as expected:
Calling another script... Being called from caller... Returned from callee...
If the call
command was dismissed in the caller, the output would be:
Calling another script... Being called from caller...
But as soon as the callee is involved in a pipe (|
), there is no difference in whether or not the call
command is used. For instance:
caller.bat
(the callee remains unchanged):
echo Calling another script...
break | callee.bat
echo Returned from callee...
The output will be this, although there is no call
command.
Calling another script... Being called from caller... Returned from callee...
What is the reason for this behaviour, what causes execution to return to the caller here?