你如何阻止从早期退出Windows批处理文件? [英] How do you stop a Windows Batch file from exiting early?
问题描述
我有一个Windows批处理文件,类似如下:
I have a windows batch file that looks similar to:
C:\DoStuff.cmd
move output.bak C:\newfolder\output.bak
我的问题是,DoStuff.cmd执行,一旦完全退出批处理回到命令提示符下的Java程序。 2号线从来没有被击中。
The problem i have is that DoStuff.cmd executes a java program that once complete exits the batch run back to the command prompt. Line 2 never gets hit.
我曾尝试以下,而不是在新窗口中执行命令:
i have tried the following instead to execute the command in a new window:
start "My program" /WAIT C:\DoStuff.cmd
move output.bak C:\newfolder\output.bak
什么跟上面的情况是,新的命令窗口派生的CMD文件运行和退出返回到等待命令提示符窗口,该窗口永远不会关闭,留下的第一个命令窗口等待和完成第一步后卡住第二无所事事。
What happens with the above is that the new command window spawns the cmd file runs and exits back to a waiting command prompt and the window never closes, leaving the first command window waiting and the second doing nothing stuck after finishing step one.
我如何无需批量运行控制它执行的第一个命令不知何故?
How do i execute the first command without it having control of the batch run somehow?
提前很多感谢
推荐答案
您可以使用 DOS调用命令:
@echo off
call C:\DoStuff.cmd
echo Exit Code = %ERRORLEVEL%
收到错误code可以继续例如使用后:
After getting error code you can proceed for example with:
if "%ERRORLEVEL%" == "1" exit /B 1
这篇关于你如何阻止从早期退出Windows批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!