Shell script window codes

Is there a standard set of return code for Windows shell scripts (* .bat files)? I am looking for something similar to Linux exit codes, where 0 == success and non-zero == failure. I need a way to programmatically check if my shell script has completed at runtime.

+3
source share
5 answers

The most common is that sames is a Unix standard, so the return code (also called errorlevel in batch files) 0 is successful, while anything above 0 is an error.

There are a number of related issues to look for - look at this guide:

Batch Files - Error Levels

+2
source

0 non-0 Windows. ERRORLEVEL, , .

if errorlevel 1 goto failure

, , .bat .

+2

.

IF :

IF [NOT] ERRORLEVEL number command

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.
+1

, Windows 0 ( ERRORLEVEL), Linux. , "", script .

script, , , script EXIT /B ##, , ##.

+1

I prefer this method:

[run an exe here]

IF %errorlevel% NEQ 0 (
    CALL :SSH_fail filename.sh %errorlevel%
)


:SSH_fail
    Email.exe "%mailTo%" "%mailProgram% - SSH Failure " "Body: errorlevel:%~2 file name: %~1"
goto cont

that way I know exactly what the error rate is. I think there can be up to 250 errors.

0
source

Source: https://habr.com/ru/post/1735461/


All Articles