Why is there no need for `call` to return from called batch script which is involved in a pipe?

十年热恋 提交于 2019-12-04 05:48:29

There are two ways to call another Batch file from the caller one (main file): call callee.bat and cmd /C callee.bat; the difference is that call execute the other Batch file in the same context of the caller program, so they share the same environment variables and another status, whereas cmd /C execute the other Batch file in an entirely separated context. Just as a personal note, I used to name internal subroutine the Batch file invoked via call, and external subroutine the one invoked via cmd /C (and overlay the Batch file directly invoked without call nor cmd /C, that inherits the behavior and context of the caller Batch file).

In the execution of a pipe, both sides of the pipe are executed via a cmd /C, so both sides are invoked as external subroutines. This way, if any side of a pipe is a Batch.BAT file, it returns to the caller program when it ends.

The same behavior happen in a callee Batch file placed in a for /F command, and exaclty for the same reason; for /F %%a in ('calle.bat') do ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!