How to know if a system command doesn't exist?

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Mon Jan 12 23:13:27 CET 2004

John J. Lee wrote:

> Nicolas Fleury <nid_oizo at yahoo.com_remove_the_> writes:
>>Nicolas Fleury wrote:
> [...]
>>>    How can I know if a system command doesn't exist?  All the ways
>>>I have tried behave like if the system command was existing but
>>>returning one.  I don't want to sound provocative, but open in Perl
> [...]
> Haven't tried popen(), but I assume C's system() (of which os.system()
> is a trivial wrapper, on posix-y OSes) is implemented in terms of
> popen() (or both are implemented in terms of similar lower-level
> stuff).  I get different return codes from system() depending on
> whether the program exists or not, as expected:

It doesn't behave like that on Windows... the return value is 1 weither 
it's the return value of the command executed of if this command doesn't 
exist.  What would be nice, I think, would be to encapsulate the 
difference, and raise an exception if the command doesn't exist.  That 
might implies additional code for Windows, but in the end the python 
code would be more portable.



More information about the Python-list mailing list