system call in python

Graham Fawcett fawcett at teksavvy.com
Thu Aug 14 02:21:42 EDT 2003


satish k.chimakurthi wrote:

>  On Thursday 14 August 2003 01:37 am, Graham Fawcett wrote:
>  
>
>>Catherine Yang wrote:
>>    
>>
>>>Hi,
>>>
>>>A question about how to execute a system command from python program. e.g.
>>>in a python script, I need to run another program written in C++, and
>>>after that come back to the same python program.
>>>
>>>
>>>      
>>>
>>Probably you are looking for os.system, as in:
>>
>>    
>>
>I think you can do the following:
>
>import commands
>commands.getstatusoutput("...your command to execture program...")
>  
>

You're right of course, and that has the benefit of returning both 
status and output.

<rant>

On an editorial aside, I'd nominate the "commands" module as a Python 
wart. It's not that the functions in this module aren't useful, but why 
are they divorced from the very-much-related commands in the "os" module?

IIWG (If I were Guido) I think I would at least sub-package this module 
as os.commands (in the spirit of os.path). While I was at it, I'd 
probably do the same for shutil (--> os.shutil).

The Python standard library is full of dark corners bearing wondrous 
mysteries, a Library of Alexandria full of useful code... but surely 
even Alexandria's librarians put similar scrolls on the same shelf!

</rant>

-- G







More information about the Python-list mailing list