Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19207
| References | <koNSq.6594$sA3.1810@newsfe01.iad> |
|---|---|
| Date | 2012-01-21 23:27 -0800 |
| Subject | Re: bufsize in subprocess |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4920.1327217278.27778.python-list@python.org> (permalink) |
On Sat, Jan 21, 2012 at 9:45 PM, <yves@zioup.com> wrote:
> Is this the expected behavior?
Yes. `.read()` [with no argument] on a file-like object reads until
EOF. See http://docs.python.org/library/stdtypes.html#file.read
> When I run this script, it reads only once, but I expected once per line
> with bufsize=1.
You want proc.stdout.readline().
http://docs.python.org/library/stdtypes.html#file.readline
> What I am trying to do is display the output of a slow process in a tkinter
> window as it runs. Right now, the process runs to completion, then display
> the result.
>
> import subprocess
>
> com = ['/bin/ls', '-l', '/usr/bin']
> with subprocess.Popen(com, bufsize=1, stdout=subprocess.PIPE,
> stderr=subprocess.STDOUT) as proc:
> print('out: ' + str(proc.stdout.read(), 'utf8'))
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bufsize in subprocess yves@zioup.com - 2012-01-21 22:45 -0700
Re: bufsize in subprocess Chris Rebert <clp2@rebertia.com> - 2012-01-21 23:27 -0800
Re: bufsize in subprocess yves@zioup.com - 2012-01-22 09:43 -0700
Re: bufsize in subprocess yves@zioup.com - 2012-01-22 10:05 -0700
csiph-web