Reputation: 31950
A Windows shell has an %ERRORLEVEL% variable that can be used to find the exit code of a process that has been run via the shell. I can therefore use this in a .bat file to obtain the exit code of an external script that I call from within the .bat file. I want to return richer error information from the process I'm calling (a stack trace in the first instance). I want to return this from a Python script that I'm running, which I can do using the Python 'traceback' module. Can I hold this in %ERRORLEVEL%? Is there any documentation for this variable?
Upvotes: 0
Views: 2134
Reputation: 85
Sometimes the lower limit for %ERRORLEVEL% is -2147483648, for example, batch file:
set /a ERRORLEVEL = -1
:LOOP
set /a ERRORLEVEL = ERRORLEVEL * 2
REM ERRORLEVEL = %ERRORLEVEL%
@pause
@Goto :LOOP
will output
REM ERRORLEVEL = -2147483648
before
REM ERRORLEVEL = 0
but the command
set /a ERRORLEVEL = -2147483648
returns "Invalid number. Numbers are limited to 32-bits of precision."
set /a ERRORLEVEL = -2147483647
works.
Upvotes: 0
Reputation: 48067
%ERRORLEVEL%
returns the exit code of program i.e., it is a integer value and does not have a character limit. As mention in wiki document for DOS:
In DOS terminology, an
errorlevel
is an integer exit code returned by an executable program or subroutine. Errorlevels typically range from 0 to 255.
The Windows section of the same document says:
Windows uses 32-bit unsigned integers as exit codes, although the command interpreter treats them as signed.
Upvotes: 2
Reputation: 147
If you're looking for returning a string, you can't assign a string to %ERRORLEVEL%
. There is documentation on %ERRORLEVEL%
here.
And you could try an environment variable- I don't code python, but I'm sure there's a way to do it in Python, and you can access them in Batch.
Also, if you know beforehand what errors will be thrown you can assign a number to each, and then exit with and have Batch output respectively. But that's boring and really unreadable, so you might not want to do that.
Upvotes: 2