popen2 question

Beej Jørgensen beej at piratehaven.org
Wed Jul 17 21:08:00 EDT 2002


In article <pan.2002.07.17.15.09.57.249439.2970 at presidency.com>,
Rajarshi Guha  <rajarshi at presidency.com> wrote:
>Input/Output Error 173: Broken pipe

A Unix process will receive SIGPIPE when it tries to write to a
two-ended file descriptor after the other end of the descriptor has been
closed.  Somehow the python end of the pipe that's hooked to fortran's
stdout is being closed before fortran is done writing to it.

>cin, cout = popen2.popen2('qnetin')
>cin.write('train\n10\n\n1000\n')
>line = cout.readline()

I think you might want

cout, cin = popen2.popen2('qnetin')
^^^^  ^^^
Maybe writing to the wrong end of the pipe messed it up somehow.  Or
maybe I have it backwards. :)  If this is the case, I can't believe it
worked at all.

>Why does the popen2 command work for the first 2 lines of output and then
>fail on the third? 

I don't know...this clashes with my suggested solution.  Are you
explicitly closing one end of the pipe before the fortran program
finished writing?  

I know this is all vague, but hopefully there's something helpful here.
YMMV.

-Beej




More information about the Python-list mailing list