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?
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.
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.
When you want to go back, type cd - and you will be back where you started.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With