determine if os.system() is done

Thomas Bellman bellman at lysator.liu.se
Wed Sep 7 06:42:27 EDT 2005


"Xah Lee" <xah at xahlee.org> writes:

> suppose i'm calling two system processes, one to unzip, and one to
> tail to get the last line. How can i determine when the first
> process is done?

> Example:

> subprocess.Popen([r"/sw/bin/gzip","-d","access_log.4.gz"]);

> last_line=subprocess.Popen([r"/usr/bin/tail","-n 1","access_log.4"],
> stdout=subprocess.PIPE).communicate()[0]

> of course, i can try workarounds something like os.system("gzip -d
> thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
> determine when a system process is done.

Have you tried reading the manual for the subprocess module?  You
just *might* find the answer to your question if you look at what
you can do with Popen objects.  Actually, just learning about the
exact semantics of the communicate() method might be enought to
solve your problem.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"I refuse to have a battle of wits with an   !  bellman @ lysator.liu.se
 unarmed person."                            !  Make Love -- Nicht Wahr!




More information about the Python-list mailing list