[Tutor] running more than one python program at the same time

Alan Gauld alan.gauld at btinternet.com
Mon Sep 3 19:55:43 CEST 2012


On 03/09/12 16:01, Benjamin Fishbein wrote:
> Hi. I started running the program in the terminal rather than IDLE. It
> works, and I can run several programs at the same time. The problem is
> that when the program is finished running, it prints:
> exit status: 0
> logout
>
> [Process completed]

That is probably writing to stderr so you can redirect the stderr output 
to a file (or /dev/null if you're feeling confident!)

$ python myprog.py myargs 2> myprog.err &

runs myprog.opy in the background and redirects stderr to the file 
myprog.err. You can then open mpyprog.err in any text editor to read it 
if you wish - hopefully it will be very boring!

> And I can't access the data that the program returned. Do I need the
> program to be saved to a text file, or is there a way to simply print it
> out? It's a small amount of data, and I'd rather just print it out.

It should print to stdout so you can see it but in general its probably 
better to redirect that to a file too... Especially if you have multiple 
programs in one terminal! So your command lines should probably look like

$ python myprog.py myargs 2> myprog.err 1> myprog.out &


HTH

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list