[Tutor] Interacting with stderr

Cameron Simpson cs at zip.com.au
Thu Aug 28 00:55:39 CEST 2014


On 27Aug2014 18:45, Crush <crushed26 at gmail.com> wrote:
>Hello, it has been a while and I hope I am sending to the correct email.
>
>How would I go about running a conditional statement against the contents of
>stderr. For instance, if "blah blah blah" is in stderr do X, else do Y.
>
>
>    #!/usr/bin/env python
>    import subprocess
>    from subprocess import PIPE
>    i = 0
>    while i < 10:
>        p = subprocess.call("avconv -v verbose -re -analyzeduration 1000 -i http://localhost:6498/ms2/1382097438004/0MediaPlayer+0+/octoshape+hVV+octolive.americaone.com+V+aone+V+live+V+ONECONNXT_DEMO1_HD_flv/aoneliveONECONNXTDEMO1HDflv -c:v rawvideo -c:a pcm_s16le -ar 48000 -f nut - | ./bmdplay -m 12 -f pipe:0", 
shell=True)
>        i += 1
>        if i == 10:
>            print "Gave up"
>
>The above code works and I get no tracebacks, however I need to add to it and
>check the contents of stderr. Avconv by default sends the audio and video to
>stdout, which then sends the signal to a capture card in the machine. Avconv
>is sending the status of the broadcasted signal i.e. frames, time, fps, etc.
>to stderr, which is displayed in the terminal.

Send stderr to a file, using a parameter like:

   stderr=open('stderr.out', 'w')

in your call() call. Then open 'stderr.out' and look for the relevant 
information.

Obviously in a "real" program you'd take care to make that a temporary file 
with a unique name using the functions from the "tempfile" module, etc. But 
make it work first.

Cheers,
Cameron Simpson <cs at zip.com.au>

The Few. The Proud. The Politically Incorrect.  - Steve Masticola


More information about the Tutor mailing list