Using subprocess to capture a progress line

Tim Johnson tim at akwebsoft.com
Wed Nov 11 11:16:57 EST 2015


* Chris Warrick <kwpolska at gmail.com> [151111 00:55]:
> On 10 November 2015 at 23:47, Tim Johnson <tim at akwebsoft.com> wrote:
> > Using python 2.7.6 on ubuntu 14.04
<..> 
> There is no \n character at the end — which means that
> p.stdout.readline() cannot return. In fact, if you printed repr() of
> the line you read, you would get this:
> 
> b'\r[download]  54.9% of 2.73MiB at 26.73KiB/s ETA 00:47\r[download]
> 55.0% of 2.73MiB at 79.33KiB/s ETA 00:15\r…snip…\r[download] 100% of
> 2.73MiB in 00:01\n'
> 
> The download line is implemented using \r, which is the carriage
> return character (return to the first character), and then by
> overwriting characters that were already printed.
> 
> The solution? There are numerous. I’ll help you by obscuring the worst one.
> 
> (1) [recommended] figure out how to make youtube_dl work as a library,
> read its main file to figure out the problem. Don’t mess with
> subprocess.
  Was my first goal, had some problems, but I have solved them in
  part by finding the good documentation of the developers.

  I.E., the subprocess method _is_ going away and I will be using
  the youtube_dl module.

> (2) [don’t do it] do you need to intercept the lines? If you don’t set
> stderr= and stdout=, things will print just fine.
  Got to try that before using the module, just for edification.

> (3) [DON’T DO IT] .ernq() punenpgre ol punenpgre naq znxr n zrff.
> 
> PS. Thank you for setting a sensible Reply-To header on your messages.
> Which is something the list should be doing.
  LOL! Glad to help :)
  Thanks for the reply and the further education. 
  Cheers
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



More information about the Python-list mailing list