FAQ
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
"

______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With NINE Servers In California And Texas - The Worlds Uncensored News Source

Search Discussions

  • Jeff Shannon at Jan 30, 2002 at 9:19 pm

    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
  • Donn Cave at Jan 30, 2002 at 10:47 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 30, '02 at 12:24a
activeJan 30, '02 at 10:47p
posts3
users3
websitepython.org

3 users in discussion

Jeff Shannon: 1 post Dave: 1 post Donn Cave: 1 post

People

Translate

site design / logo © 2021 Grokbase