subprocess -- broken pipe error

7stud bbxx789_05ss at yahoo.com
Mon Jul 2 14:19:05 EDT 2007


On Jul 2, 11:32 am, "holden... at gmail.com" <holden... at gmail.com> wrote:
> On Jul 2, 1:12 pm, 7stud <bbxx789_0... at yahoo.com> wrote:
>
>
>
> > Hi,
>
> > Can someone explain what a broken pipe is?  The following produces a
> > broken pipe error:
>
> > ----------
> > import subprocess as sub
>
> > p = sub.Popen(["ls", "-al", "../"], stdin=sub.PIPE, stdout=sub.PIPE)
>
> > print p.stdout.read()
> > #outputs the files correctly
>
> > p.stdin.write("ls\n")
> > #IOError: [Errno 32] Broken pipe
> > -----------
>
> You are seeing this error because sub.Popen closes both stdin and
> stdout once the subprocess terminates (which it must have done for
> p.stdout.read() to return a result).
>
> Consequently you are trying to write to a pipeline whose reader has
> already closed it, hence the error message.
>
> regards
>  Steve

Hi,

Thanks for the response.  So are you saying that the only way you can
get data out of a pipe is when the subprocess has terminated?




More information about the Python-list mailing list