difference between running another batch script by its name and by using call

You can invoke another batch script from a batch script like this:

rem a.bat
echo helloa1
b.bat
echo helloa2

 

rem b.bat
echo hellob1
exit /b
echo hellob2

Here, the batch script a.bat invokes another batch script b.bat. You may expect it displays “helloa1″,”hellob1”, and “hello a2”. But it only shows the first two. This is because when you run another script by directly using its name, the current script stops, and the execution flow never goes back to the current script again. This is probably not what you want. You may want the first script continues after the second script terminates. To do that, you need to run the second script from the first script using “call” as follows:

rem a.bat
echo helloa1
call b.bat
echo helloa2

Now, after b.bat exits(note that exit /b will not terminate the cmd.exe that executes the scripts), a.bat continues. See this post for a discussion.

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply