[Tutor] Interacting with stderr
Cameron Simpson
cs at zip.com.au
Thu Aug 28 02:58:33 CEST 2014
Before we proceed, two requests:
Please do not top post. Post below, and trim the irrelevant content, so things
read like a conversation.
Please consider reading the list on an article-by-article basis instead of as a
digest. You will get a better discussion view and we will see your messages in
a nice threaded chain. By replying to a digest you have broken the chaining
(because the digest is not part of the chain). If you find it noisy, just add a
filter to your mailer to send list messages to their own folder. For example, I
have a "python" mail folder which receives several python related lists,
keeping it out of my main inbox.
Returning to your subprocess questions...
On 27Aug2014 20:28, Crush <crushed26 at gmail.com> wrote:
>As far as sending the contents of stderr to a tmp file...hmmm, i
>will try that. My only concern is, many of these systems run live
>demo feeds for many days...10+. Im afraid the file will fill up
>very quickly and present problems.
Ok. Then a file may not be entirely suitable to your task.
>Stderr=PIPE causes the terminal to hang. I can not wait for the process to terminate, i need to read stderr as it is being fed data.. Would fifos be of any use here?
First off, stderr=PIPE _is_ a FIFO; it constructs a pipe between the subprocess
and your python program.
However, if you need to read the stream as it occurs then you should not use
"call()", which inherently waits for the command to finish.
Instead, use the Popen constructor (also part of the subprocess module).
Crude and incomplete and untested example:
from subprocess import Popen, PIPE
P = Popen("avconv ... lots of arguments...", shell=True, stderr=PIPE)
for line in P.stderr:
... examine the line from stderr ...
# ok, we have read all of stderr now
xit = P.wait()
if xit != 0:
... command was unsuccessful, complain, maybe abort ...
Cheers,
Cameron Simpson <cs at zip.com.au>
ep0: 3c509 in test mode. Erase pencil mark!
This means that someone has scribbled with pencil in the test area
on the card. Erase the pencil mark and reboot. (This is not a joke).
- OpenBSD 2.3 ep(4) ethernet drive manual entry
More information about the Tutor
mailing list