Python equivalent of shell's '$?'

Graham Ashton gashton at cmedltd.com
Fri May 31 07:08:13 EDT 2002


On Fri, 2002-05-31 at 11:07, Dave Swegen wrote:

> If I call an external program from a python script, how do I check that
> programs exit status?

It's the return value of os.system. Unless you're on win9x. You're not,
are you?

> Or does python suffer from
> the same unreliabilty as perl in this regard

I never had any problem with this in five years of Perl, almost
exclusively on Linux. What platform are you running on?

> (I've learnt that catching
> errors from sub shells is highly unreliable, and ended up having not
> checking for errors, as I would sometimes get spurious results back).

This suggests you're on windows, which is crap at launching other
processes in a simple manner. To get round many of the problems you have
to use stuff from the windows API, as the command interpreter is utter
fudge.

Your reference to sh makes me hopeful that you're on a more sensible
system than that though...

-- 
Graham Ashton






More information about the Python-list mailing list