Command shell access within Python

Pierre Rouleau pieroul at attglobal.net
Sun Nov 4 15:14:31 EST 2001


Thanks for taking the time to answer Stefan.


> > I also need to get the return code (c exit()) of the program that ran.
> os.system() gives you the return code of your command.
> try interactively:
>
> import os
>
> print os.system('ls')
>
> ... listing ...
> 0 <-- return code

Actually, i knew that i can execute a single program inside a command shell and get the return code.
What i want is to execute a large set of commands inside the same shell process and being able to get the return code for exach one
of the calls.

For example,  i would like to be able to do someting like:

myShell = Process('cmd')
error = myShell.execute('make myproject')
if (error == 0) :
    myShell.execute('ls')
    myShell.execute('pj ci makefile')


I want to be able to issue a whole list of line commands whithout having to create a new process on every one of them.


Pierre






More information about the Python-list mailing list