popen writes to a shell but wont read

Donn Cave donn at u.washington.edu
Wed Jan 30 17:47:37 EST 2002


Quoth Jeff Shannon <jeff at ccvcorp.com>:
...
| Just a wild guess, but you might try flushing after you write...
|
|         w.write(passwd)
|         w.flush()
|
| If your file object is buffered (and I *think* that popen-returned objects are), then
| the shell process will not actually receive the data until the buffer is flushed.

That's quite true, and flush() will definitely help.

If it still doesn't work, that's probably because something on the other
end of the pipe has the same problem.  Which more or less inevitably, it
will.  In this case the solution is much more difficult, but will solve
another possible problem too (if the other end is aborting because some
tty specific ioctl failed.)  That's a pseudotty, or pty for short.  There's
a module, pty, and a couple of functions that may be supported in the
posix module, getpty() and forkpty().  A pseudotty is a cross between a
duplex pipe and a tty device.  Because it looks like a tty, applications
"line buffer" their output, as opposed to "block buffer".

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list