How to conditionally write a call command in a batch file?

I have two lines of a call command in a batch file:

call execute.cmd
call launch.cmd

I need to call launch.cmd if and only if the call to execute.cmd is complete. So, is it possible to somehow establish some conditions?

execute.cmd does not return any value here.

+5
source share
2 answers

If it execute.cmdreturns an integer than you can use IF commandto check its return value and if it matches what you want, you can calllaunch.cmd

Suppose it execute.cmdreturns 0 if it is successful, or an integer> = 1 otherwise. The package will look like this:

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

+5

, ?.

:

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.

+3

All Articles