Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何有条件地在批处理文件中写入call命令?_Batch File - Fatal编程技术网

Batch file 如何有条件地在批处理文件中写入call命令?

Batch file 如何有条件地在批处理文件中写入call命令?,batch-file,Batch File,我在批处理文件中有两行调用命令,如下所示: call execute.cmd call launch.cmd 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

我在批处理文件中有两行调用命令,如下所示:

call execute.cmd
call launch.cmd
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
我需要在调用execute.cmd成功时调用launch.cmd。 那么,有什么方法可以在这里设置一些条件吗


execute.cmd在此不返回任何值。

如果
execute.cmd
返回一个整数,则可以使用a检查其返回值,如果它与所需值匹配,则可以调用
launch.cmd

假设
execute.cmd
成功返回0,否则返回整数>=1。批处理将如下所示:

call execute.cmd
call launch.cmd
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
请注意,
rem
命令用于注释


嗯,
JP

我相信这是一个复制品

您的解决方案是:

call execute.cmd
if %errorlevel% neq 0 exit /b %errorlevel%
call launch.cmd
if %errorlevel% neq 0 exit /b %errorlevel%

不幸的是,Windows批处理文件似乎没有UNIX bash的
set-e
set-o pipefail
的等价物。如果您愿意放弃非常有限的批处理文件语言,您可以尝试Windows PowerShell。

exceute.cmd如果成功,则返回0,如果不成功,则返回1,因此使用您的逻辑解决了问题,非常感谢。正如你首先回答的,我接受你的答案,即使@jhclark的答案看起来是正确的。@Anand K Gupta your wellcome:)你也可以通过以下方式实现Windows批处理和组合:call execute.cmd&&call launch.cmd