Reading from a pipe (open mode w)

Erno Kuusela erno-news at erno.iki.fi
Thu Jan 4 09:42:48 EST 2001


In article <931d5j$m0e$1 at proxy.fe.internet.bosch.de>, "Jens
Vogelgesang" <jens.vogelgesang at de.bosch.com> writes:

| I can generate the input by writing into the pipe.
| To be able to retrieve the tool output, I tried to read from the pipe.

you can't read from a file or pipe that is opened in write mode.

there is the popen2 module, but it is can cause deadlocks
when you try to read from one pipe when the program at the
other end is waiting for you to write something. details
in the docs.

it might be better to use a temporary file and a unidirectional
pipe, like os.popen('program < input.tmp', 'r')

| My Problem is, that I don't know, how to flush the pipe

you can use the flush() method of the file object in question.

| to force the pipe not to be buffered??

the os.popen() function takes an optional 3rd argument for buffering
parameters, just like the open() built-in. details in the docs.

  -- erno



More information about the Python-list mailing list