how to write .bat file to bail-out

  • Thread starter Thread starter John A Grandy
  • Start date Start date
"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
how to write a .bat file to bail-out if any command-line triggers an error?

=================

after any command which can fail put:
if errorlevel 1 goto enderror

and at the end of the batch which is the place the goto references.

:enderror
echo an error has occured and the program has aborted.
 
In Windows 2000 and newer, add:

|| GOTO :EOF

after each command that you want to check for failure.
If the command to the left of that fails, the batch file will quit/exit.
Two pipe symbols space GOTO space colon EOF
EOF stands for End Of File. You DO NOT need to create a label called EOF.
It is understood as the "end of your batch file".

Example:
DIR Q: || GOTO :EOF
TYPE FILENAME.EXT || GOTO :EOF

Austin M. Horst
 
Back
Top