A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/307731.html below:

determine if os.system() is done

determine if os.system() is doneMartin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Thu Sep 8 04:12:21 EDT 2005
Xah Lee wrote:
> suppose i'm calling two system processes, one to unzip, and one to
> “tail” to get the las
t 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 know you've found the answer to your question, however for the exact
example you gave a much better solution comes to mind...


import gzip

log_file = gzip.open("access_log.4.gz")
last_line = log_file.readlines()[-1]
log_file.close()


Regards
Martin






More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4