[Tutor] Interacting with stderr

Crush crushed26 at gmail.com
Fri Aug 29 23:13:02 CEST 2014


I am now able to print stderr to the screen, however I still can not run conditional statements against stderr. 

Please see the screenshots(SS) here...

https://www.dropbox.com/sh/31wyjtvqymo94uk/AAAZaxwB27nw1nmz7tz69I5La?dl=0

Bo 

> On Aug 28, 2014, at 6:12 PM, Cameron Simpson <cs at zip.com.au> wrote:
> 
>> On 28Aug2014 09:42, Crush <crushed26 at gmail.com> wrote:
>> As far as the pipe in...
>> 
>> "avconv -v verbose -re -analyzeduration 1000 -ihttp://localhost:6498/ms2/1382097438004/0MediaPlayer+0+/octoshape+hVV+octolive.americaone.com+V+aone+V+live+V+ONECONNXTDEMO1_HD_flv/aoneliveONECONNXTDEMO1HDflv -c:v rawvideo -c:a pcm_s16le -ar 48000 -f nut - | ./bmdplay -m 12 -f pipe:0"
>> 
>> ...it has to be there.
> 
> Indeed. We're not arguing about that. Leave it there for.
> 
>> Currently, i am running a shell script that is handling this decoding process i.e. the real long avconv/bmdplay command. So you are saying leave the shell script and invoke it from a python script...something like "p = subprocess.Popen("./my_script.sh")? How will the above allow me to interact with stderr in oppose to running the avconv/bmdplay command directly in python?
> 
> No, we're no saying that.
> 
> You could (and presumably do) have this long incantation in your shell script.  As far as the Python stuff goes, that does not change anything: you can invoke your shell script or invoke your long command directly. Either way you need to grab the stderr on the fly and work with it.
> 
> Personally, I would keep the pipeline in the shell script where it is easier to edit and invoke the script from Python (easier to read). Your call.
> 
>> As far as not using "shell=True," if I dont have it set to True, the terminal hangs and will not display stderr to the screen as it is currently does.
> 
> Let's tackle shell=True later.
> 
> What you need to do is examine stderr before the shell script/pipeline is complete, and for that you need to separate starting the process, reading stderr, and waiting for process completion into distinct parts, which was what my example code was doing. I'll recite it again here:
> 
>  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 ...
> 
> Please try adapting your Python code to that and see where you end up.
> Put a print statement as the first line in the for-loop so you can see if you are receiving stderr lines as intended.
> 
> Cheers,
> Cameron Simpson <cs at zip.com.au>
> 
> As soon as we started programming, we found to our surprise that it wasn't as
> easy to get programs right as we had thought. Debugging had to be discovered.
> I can remember the exact instant when I realized that a large part of my life
> from then on was going to be spent in finding mistakes in my own programs.
>        - Maurice Wilkes discovers debugging, 1949
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140829/e1ca45ed/attachment.html>


More information about the Tutor mailing list