system call in python

Graham Fawcett fawcett at teksavvy.com
Thu Aug 14 01:37:22 EDT 2003


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.
>
>Is it the system module, and which function do I use to do this?
>
>Thanks a lot
>Catherine
>
>
>  
>
Probably you are looking for os.system, as in:

    import os
    cmd = 'ls -l /usr/bin'
    os.system(cmd)

Note that this will not capture the output of the system command; you 
can use the os.popen family of commands to do that.

-- Graham






More information about the Python-list mailing list