Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exceptions versus Windows ERRORLEVEL

87 views
Skip to first unread message

Stephen Tucker

unread,
Apr 3, 2020, 7:09:02 AM4/3/20
to
Hi,

I have found that raising an exception in a Python 2.7.10 program running
under Windows does not set ERRORLEVEL.

I realise that Python 2.x is no longer supported.

Does an exception raised by a Python 3.x program on a Windows machine set
ERRORLEVEL?

If not, are there plans for it to do so?

Stephen.

Stephen Tucker

unread,
Apr 3, 2020, 2:15:31 PM4/3/20
to

Luuk

unread,
Apr 4, 2020, 10:32:45 AM4/4/20
to
It seems to do so:
D:\TEMP>type test.py
print(1/0);

D:\TEMP>python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
print(1/0);
ZeroDivisionError: division by zero

D:\TEMP>echo %ERRORLEVEL%
1

D:\TEMP>python -V
Python 3.8.0

D:\TEMP>

--
Luuk

Luuk

unread,
Apr 4, 2020, 10:44:08 AM4/4/20
to
On 3-4-2020 02:08, Stephen Tucker (Stephen Tucker) wrote:
> Hi,
>
> I have found that raising an exception in a Python 2.7.10 program running under
> Windows does not set ERRORLEVEL.
>
> I realise that Python 2.x is no longer supported.
>
> Does an exception raised by a Python 3.x program on a Windows machine set
> ERRORLEVEL?
>
Yes, it does.

Luuk

unread,
Apr 4, 2020, 8:15:23 PM4/4/20
to

Eryk Sun

unread,
Apr 6, 2020, 1:43:29 AM4/6/20
to
On 4/3/20, Stephen Tucker <stephen...@sil.org> wrote:
>
> Does an exception raised by a Python 3.x program on a Windows machine set
> ERRORLEVEL?

ERRORLEVEL is an internal state of the CMD shell. It has nothing to do
with Python. If Python exits due to an unhandled exception, the
process exit code will be 1. If CMD waits on the process, it will set
the ERRORLEVEL based on the exit code. But CMD doesn't always wait. By
default its START command doesn't wait. Also, at the interactive
command prompt it doesn't wait for non-console applications such as
"pythonw.exe"; it only waits for console applications such as
"python.exe".

Stephen Tucker

unread,
Apr 6, 2020, 5:05:10 AM4/6/20
to
Thanks, Eryk - this is very helpful.

Stephen.

Stephen Tucker

unread,
Apr 6, 2020, 3:15:33 PM4/6/20
to

Eryk Sun

unread,
Apr 6, 2020, 3:15:40 PM4/6/20
to
0 new messages