determine if os.system() is done
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Wed Sep 7 07:12:10 EDT 2005
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/
>
I think the idea is you wait for the first call to subprocess.call to
finish before executing the second...
http://docs.python.org/lib/node231.html
call( *args, **kwargs)
Run command with arguments. *Wait for command to complete*, then
return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
More information about the Python-list
mailing list