我在批处理文件中有两行调用命令,如下所示:
call execute.cmd
call launch.cmd
Run Code Online (Sandbox Code Playgroud)
当且仅当对execute.cmd的调用成功时,我才需要调用launch.cmd.那么有什么办法可以在这里提出一些条件吗?
execute.cmd在这里不返回任何值.
如果execute.cmd返回一个整数,那么你可以用a IF command来检查它的返回值,如果它与你想要的那个匹配,那么你可以调用它launch.cmd
假设execute.cmd如果成功则返回0,否则返回> = 1.批处理看起来像这样:
rem call the execute command
call execute.cmd
rem check the return value (referred here as errorlevel)
if %ERRORLEVEL% ==1 GOTO noexecute
rem call the launch command
call launch.cmd
:noexecute
rem since we got here, launch is no longer going to be executed
Run Code Online (Sandbox Code Playgroud)
请注意该rem命令用于注释.
HTH,
JP