Don’t trust python’s os.execv
Python is nice and all, but its low-level functions have real disruptive discrepancies between platforms.
Case at point:
import os os.execvp("sh", ["sh", "-c", "exit 1"])
As a UNIXy person, I'd expect running the above script to return an error code of 1. And I would be perfectly right... on UNIX systems.
On Windows, it returns 0.
You'd think such a difference in behavior would be documented? It's not.
Thank you python.
2013-11-23 01:24:26+0900
Responses are currently closed, but you can trackback from your own site.
2013-11-23 05:57:09+0900
Is this a Python issue, or a Windows issue? If Windows is setting the return code to 0, then what is Python to do about it?
2013-11-23 10:34:08+0900
Sounds silly to blame this on Python…
But, why make stuff that works on Windows anyway??
2013-11-23 19:13:37+0900
Wild guess, but if you’re using cygwin, could this have something to do with this?
http://cygwin.com/ml/cygwin/2005-01/msg01382.html
2013-11-24 00:31:52+0900
@Erik … What is Python to do about it? What about documenting it?
2013-11-24 06:40:55+0900
@MatÄ›j – What is there to document? execv() has the same behavior on both Windows and Unix, which is to fire off a new process and let it run. Then you start up sh, presumably a cygwin binary. sh exits with a return code of zero on Windows. At the point at which you see the behavior, Python isn’t even running, as you’ve exec’ed into sh. That may be weird, but if it’s weird, it is either Windows or your sh binary. Python is having identical behavior across platforms.
2013-11-24 09:57:38+0900
@Erik execv() does *not* create a new process. It replaces the existing process.
2013-11-25 07:57:05+0900
Found a bug in the Python documentation? Please submit a bug report/patch to the Python project => bugs.python.org
2013-11-25 09:10:49+0900
Hit me too. I now use subprocess.call on Windows in Nuitka as well. Which is a pity, because it really would want to stop the original process right then and now it lives on just to eait for exit code to then exit with the same.
Kay