why does close() fail miserably on popen with exit code -1 ?!

Donn Cave donn at drizzle.com
Mon Feb 20 12:05:59 EST 2006


Quoth "Atanas Banov" <enterr at gmail.com>:
| i ran onto this weirdness today: seems like close() on popen-ed
| (pseudo)file fails miserably with exception instead of returning exit
| code, when said exit code is -1.
|
| here is the simplest example (under Windows):
|
| >>> print popen('exit 1').close()
| 1
| >>> print popen('exit -1').close()
| Traceback (most recent call last):
|   File "<interactive input>", line 1, in ?
| IOError: (0, 'Error')
| >>> print popen('exit -2').close()
| -2
|
| has anyone have idea why is that?

I have no idea about Microsoft Windows, and I doubt that you could
reproduce this on UNIX, but neither does this look like a valid
UNIX program.  Exit codes are integer values in the range [0..255],
so there are no negative numbers (which is what I think you intended),
nor are there strings (which is what '-1' would have been with the
classic UNIX shell.)

So I will leave it to someone else to wrestle with the Microsoft
problem, but I just wanted to point out that it isn't something you
could expect to work anywhere else.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list