Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to view a command return code in DOS

Sometimes I run a command in cmd such as:

fc /b file1 file2 

and would like to see the return code from fc. Is there a simple way to do this?

like image 231
Warpin Avatar asked Mar 26 '10 08:03

Warpin


People also ask

What is the command to check exit code?

How to find out the exit code of a command. echo $? printf '%d\n' $? From the above outputs, it is clear that the exit code is 0 indicates that date command was successful.

How can I see all DOS commands?

Type help and press ↵ Enter . A list of all the available commands will be displayed. The listed is sorted alphabetically. The list is usually larger than the Command Prompt window, so you may need to scroll up to find the command you want.

How do I go back in DOS command?

When you want to go back, type cd - and you will be back where you started.

How do I echo in DOS?

To display the command prompt, type echo on. If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command.


1 Answers

echo %ERRORLEVEL% 

From TechNet, Command shell overview: "%ERRORLEVEL% ... Returns the error code of the most recently used command. A non zero value usually indicates an error."

To test for specific error levels in batch files, you may find this knowledgebase article useful.

like image 56
Andras Vass Avatar answered Sep 20 '22 17:09

Andras Vass