Sep 09 2008
Windows Shell Exit/Return Code Variable
After running a command in Unix, the status of the command (usually a simply success or failure, 0/1) can be found by echoing the $? environment variable.
Of course, you can do this in Windows too, but I guess no one really does because it is hard to find searching the Internet. So, to determine an application’s exit code from a Windows shell, first run it, and then echo the value of the environment variable %ERRORLEVEL%. This should give you the same information as the relevant command in Unix.
C:\Documents and Settings\mfaus>dir doesNotExist
Volume in drive C has no label.
Volume Serial Number is F08F-730C
Directory of C:\Documents and Settings\mfaus
File Not Found
C:\Documents and Settings\mfaus>echo %ERRORLEVEL%
1
C:\Documents and Settings\mfaus>dir NewDirectory
Volume in drive C has no label.
Volume Serial Number is F08F-730C
Directory of C:\Documents and Settings\mfaus\NewDirectory
09/09/2008 04:39 PM
09/09/2008 04:39 PM
0 File(s) 0 bytes
2 Dir(s) 172,309,262,336 bytes free
C:\Documents and Settings\mfaus>echo %ERRORLEVEL%
0
Hope this helps someone out there!
Well I certainly feel enlightened. I was looking for a Windows exit code just the other day. Of course this is greek to me but I appreciate the detail and work that you must have put in to accomplish this solution. Way to go. I love you, Mom
Haha, thanks mom. It really didn’t take much time to figure out, I just had to dig around on the Internet longer than 5 minutes. Hopefully, the next time someone else searches for these keywords this blog post will show up #1 in Google and answer their question immediately.
This was useful for me, although it wasn’t #1 Google search result.
;D
This works. Gracias!
THank you! (It was #1 google search result.)