This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients ezio.melotti, gvanrossum
Date 2014-01-03.22:20:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1388787639.9.0.977617126521.issue20117@psf.upfronthosting.co.za>
In-reply-to
Content
A little birdie told me:

"""
Bug in Python subprocess doesn't allow to detect if
command executed through Windows system shell
exists.

If command doesn't exist, windows shell returns 9009
exit code (127 on Linux):
---[a.bat]---
@echo off
nonex
echo %ERRORLEVEL%

> a.bat
'nonex' is not recognized as an internal or external command,
operable program or batch file.
9009

However, when executed with Python, the return code
is different on Python 2.7/3.3:
---[x.py]---
import subprocess
p = subprocess.Popen("nonex", shell=True)
print(p.wait())

> python x.py
'nonex' is not recognized as an internal or external command,
operable program or batch file.
1

The same script executed on Linux gives correct result:
# python x.py
/bin/sh: non-existent: command not found
127

---[a.sh]---
nonex
echo $?
"""

There's some more research at http://goo.gl/xEg2b1

Seems the culprit is cmd.exe, which is executed by Python internally.
It looks like it fails to return corresponding code 9009.

Possibly all that needs to be done is documenting this wart, if we can't do anything about it?
History
Date User Action Args
2014-01-03 22:20:39gvanrossumsetrecipients: + gvanrossum, ezio.melotti
2014-01-03 22:20:39gvanrossumsetmessageid: <1388787639.9.0.977617126521.issue20117@psf.upfronthosting.co.za>
2014-01-03 22:20:39gvanrossumlinkissue20117 messages
2014-01-03 22:20:39gvanrossumcreate