We help IT Professionals succeed at work.

Exit status of a command

ostraaten
ostraaten asked
on
4,239 Views
Last Modified: 2010-08-05
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.

Comment
Watch Question

Retired
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gary CaseRetired
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2009

Commented:
... 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.

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.