Python equivalent of shell's '$?'

Dave Swegen dswegen at software.plasmon.com
Fri May 31 08:23:24 EDT 2002


On Fri, May 31, 2002 at 12:08:13PM +0100, Graham Ashton wrote:
> 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?
> 

Nope. In this case it was FreeBSD.

> > 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.

I can't quite remember exactly what the problem was (I seem to recall
that the errno returned was not what the called program returned). This
was using both open and backticks. It was yet another nail in the coffin
that is my opinion of perl ;)

I should point out that I am no expert in perl (nor do I wish to become
one, either).

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

Too bloody right I am! :)

Cheers
    Dave





More information about the Python-list mailing list