popen writes to a shell but wont read
Jeff Shannon
jeff at ccvcorp.com
Wed Jan 30 16:19:00 EST 2002
dave wrote:
> Im trying to use popen3 to read and write to s shell process. The write
> bit seems to complete but the read doesnt return. looks like blocking
> but using '`b' in popen makes no difference either.
>
> "
> #invoke a root shell
> whoami=string.strip(os.popen(luser).read())
> if whoami != 'root':
> w,r,e =os.popen3(rootshell) #w,r,e order makes no difference
> try:
> w.write(passwd)
> except Exception, ex:
> raise Exception, ex+"password failure"
> print r.read() #waits here forever
> "
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.
You may also wish to try to set up a timeout on your read() ...
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list