Difference between call and cmd /c in windows batch

柔情痞子 提交于 2019-12-01 03:45:21

问题


Can someone please explain what's the difference between

call someBatchFile.bat ...

And

cmd /C someBatchFile.bat ...

They both were suggested to me as solutions to this problem, but I don't understand why they both work, and more importantly, if there are any significant differences I must be aware of.


回答1:


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 other status (like echo ON/OFF or delayed expansion), whereas cmd /C execute the other Batch file in an entirely separated context, so any change made in the called Batch file is not reflected in the original file.

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).



来源:https://stackoverflow.com/questions/39055349/difference-between-call-and-cmd-c-in-windows-batch

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