Application Delivery Management
Application Modernization & Connectivity
CyberRes
IT Operations Management
How to determine the exit status of a command executed on UNIX and Windows?
PROBLEM/ABSTRACT:
How to determine the exit status of a command executed on UNIX and Windows?
SOLUTION:
A return value of zero (0) indicates the command completed without error. A non zero value indicates the command failed. To determine the return value you will run the following command.
UNIX:
echo $?
Example:
# ls
foo.c
# echo $?
0
# ls -z
ls: invalid option -- z
Try `ls --help' for more information.
# echo $?
1
Windows:
echo %ERRORLEVEL%
Example:
C:\>dir
Volume in drive C has no label.
Volume Serial Number is 5C83-6C21
Directory of C:\
02/08/2006 11:49 AM <DIR> .
02/08/2006 11:49 AM <DIR> ..
01/18/2006 10:58 AM 57 foo.c
C:\>echo %ERRORLEVEL%
0
C:\>dir bar.c
Volume in drive C has no label.
Volume Serial Number is 5C83-6C21
Directory of C:\
File Not Found
C:\>echo %ERRORLEVEL%
1
For more information contact AccuRev Support