James Ray Anderson

James Ray Anderson
James Ray Anderson
0 comments

PSEXEC Error Code 1

10:09 AM
If you get "error code 1" when invoking a batch file the likel cause is the EXIT command.  Just performing an exit closes the batch file normally, but terminates the cmd.exe.  To avoid this use the /b option on the exit command.

Example:       exit
Explanation:  You will get a "return code 1".  Setting the ERRORLEVEL has no effect.

Example:       exit /b 0
Explanation: exits the batch file, closes the cmd.exe, and sets the return code to zero.

Example:       exit /b -2
Explanation: exits the batch file, closes the cmd.exe, and sets the return code to zero

I write my batch files with GOTO statements that control the exit and return code.  This is an example of a batch file that reads a log file line-by-line and examines it for the success/failure string.  For example:
@echo off
for /F "delims=" %%a in ("result.log") do (
     if "%%a" EQU "success" goto SUCCESS
     if "%%a" EQU "failure" goto FAILURE
)
:FAILURE
exit /b -2
 :SUCCESS
exit /b 0

0 comments:

 
Toggle Footer
Top