determine if os.system() is done

Xah Lee xah at xahlee.org
Thu Sep 8 01:07:08 EDT 2005


Thanks all.

I found the answer, rather easily.
To make a system call and wait for it, do:

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

------
this post is archived at:
http://xahlee.org/perl-python/system_calls.html

 Xah
 xah at xahlee.orghttp://xahlee.org/


Xah Lee wrote:
> 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.
> 
>  Xah
>  xah at xahlee.org
>http://xahlee.org/




More information about the Python-list mailing list