eTechtips

Tech Tips and Insights

DOS: Capture return values from commands

When I am writing build automation scripts, there are times that I have to insure that the previous command completed
with no errors. I have found that ERRORLEVEL gets filled in with the return value from a command.

dir %1

if (%ERRORLEVEL%) == (0) echo Found File: %1
if (%ERRORLEVEL%) == (1) echo Missing File: %1

So if you save the previous in a file and run the command with one (1) argument, it will display the output of the dir command
but also print either “Found file: ” or “Missing File: “.

Loading

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.