subprocess -- broken pipe error

holdenweb at gmail.com holdenweb at gmail.com
Mon Jul 2 13:32:57 EDT 2007


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




More information about the Python-list mailing list