Link to home
Start Free TrialLog in
Avatar of ostraaten
ostraaten

asked on

Exit status of a command

I'm running the Tidy.exe from a DOS prompt in Windows XP. How can i see what the exit status is of running the command?

I like to know if the program was executed succesful or not.

ASKER CERTIFIED SOLUTION
Avatar of Gary Case
Gary Case
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... I presume it's obvious, but to run the above, you just type RunTidy from a command prompt;  or just double-click on the icon if you created a shortcut to it.

If it uses arguments, you would just type RunTidy <Arg1> <Arg2>
... but of course need to have those arguments in the line I indicated earlier.   For example, if Tidy.exe uses 2 arguments, the 2nd line of the batch file would be:
Tidy.exe %1 %2

... and then when you typed RunTidy with two arguments, those would be "passed" to the Tidy command.
Avatar of ostraaten
ostraaten

ASKER

Thanks, that was what I was looking for, I'm running from the command prompt and with echo %ErrorLevel% I can confirm that it outputs 0 fo success, 1 for warnings and 2 for errors.
If you are talking about HTML Tidy from here:
http://www.w3.org/People/Raggett/tidy/
the there is an additional Exit Code in addition to the 0 = success and 1 = fail.

0 = All input files were processed successfully.
1 = There were warnings.
2 = There were errors.

http://tidy.sourceforge.net/docs/tidy_man.html

http://tidy.sourceforge.net/docs/tidy_man.html#EXIT%20STATUS

If you look at the options that you can use with that program, you can generate a log file that tells you the status and results of the process:

http://tidy.sourceforge.net/docs/tidy_man.html#OPTIONS

-file <file>, -f <file>

Writes errors and warnings to the specified <file> (error-file: <file>)
 
garycase has given the best method if you really want to see the exit codes in real time, ie. by sending the batch file to different labels if the error exit code was present.  Expanding on it, just add in another one with an appropriate message echoed to screen. I've used my own preferences in the batch file, but there's nothing at all wrong with gary's.

@echo Off
::
tidy /options params
::
:: See http://tidy.sourceforge.net/docs/tidy_man.html#OPTIONS
::
if errorlevel 2 goto :ERR
if errorlevel 1 goto :WARN
rem the line below is not needed, but is included for completeness
if errorlevel 0 goto :OK
::
:OK
echo.
echo The process was a success
echo.
echo press any key to quit ...
pause > nul
goto :END
::
:WARN
echo.
echo The process completed, but with warnings!
echo.
echo press any key to quit ...
pause > nul
goto :END
::
:ERR
echo.
echo The process did not complete.  There were errors!!
echo.
echo press any key to quit ...
pause > nul
goto :END
::
:END
EXIT

Open in new window