欲了解更多信息,请访问此问题How to execute a batch script (child.bat) from a batch file (parent.bat)?
为了将控制权传递回父批处理文件,必须使用CALL 命令调用子批处理文件。
CALL batch1.bat F:\_FFMPEG_\bin\01.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\
CALL batch1.bat F:\_FFMPEG_\bin\02.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\
CALL batch1.bat F:\_FFMPEG_\bin\03.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\
举例
child.bat
@echo off
echo Child Batch File is running !!!
echo Doing some Important Child Batch Stuff here . . . .
echo ✔ Child Batch Completed it. Voila !!
echo Now exiting Child.bat
parent.bat
@echo off
echo Parent Batch File is running !!!
echo Doing some Important Stuff here . . . .
echo ✔ Completed it. Voila !!
echo Now running Child.bat . . .
echo -------------------------------------------------------
child.bat
rem Comment: Some how below statements are not executing
echo -------------------------------------------------------
echo ✔ Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.
这将运行:
C:\Users\abc> parent.bat
Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat
C:\Users\abc>
不会执行其他语句。
要纠正这个使用CALL:
child.bat 不会改变
@echo off
echo Child Batch File is running !!!
echo Doing some Important Child Batch Stuff here . . . .
echo ✔ Child Batch Completed it. Voila !!
echo Now exiting Child.bat
parent.bat 使用CALL 执行*.bat 脚本
@echo off
echo Parent Batch File is running !!!
echo Doing some Important Stuff here . . . .
echo ✔ Completed it. Voila !!
echo Now running Child.bat . . .
echo -------------------------------------------------------
rem Comments: CALL will execute the .bat and return the cmd context back to the parent.bat for further execution.
CALL child.bat
echo -------------------------------------------------------
echo ✔ Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.
输出:
Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat
-------------------------------------------------------
Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.
一些参考资料:
CALL | Microsoft Docs