如何从批处理脚本中运行批处理脚本?
如何从批处理脚本中调用另一批处理脚本?
我希望它在if语句中执行。
在CALL中使用
CALL nameOfOtherFile.bat
这将阻塞(暂停)当前batch file的执行,并且将一直等到CALL编辑完成。
如果您不希望它阻止,请使用START 。
通过使用CALL /?获取细节的细节 或START /? 从cmd提示符。
您可以通过名称来调用批处理脚本,就好像您在命令行上运行一样。
所以,假设你有一个文件bar.bat ,说echo This is bar.bat! 你想从foo.bat文件中调用它,你可以在foo.bat中foo.bat :
if "%1"=="blah" bar
从命令行运行foo blah ,你会看到:
C:\>foo blah C:\>if "blah" == "blah" bar C:\>echo This is bar.bat! This is bar.bat!
但要小心 :从另一批处理脚本调用批处理脚本时,原始批处理脚本将停止运行。 如果要运行辅助批处理脚本,然后返回到以前的批处理脚本,则必须使用call命令。 例如:
if "%1"=="blah" call bar echo That's all for foo.bat!
如果你运行foo blah ,你会看到:
C:\>foo blah C:\>if "blah" == "blah" call bar C:\>echo This is bar.bat! This is bar.bat! C:\>echo That's all for foo.bat! That's all for foo.bat!
你应该使用CALL
CALL batch.bat
这里是例子:
你有a.bat:
@echo off if exist b.bat goto RUNB goto END :RUNB b.bat :END
和b.bat有条件地从a.bat中调用:
@echo off echo "This is b.bat"
您可以使用
call script.bat
要不就
script.bat