popen2.popen2,3,4 from Python 2.0 on NT 4.0 SP5

Jake Speed speed at ?.com
Mon Oct 30 17:20:35 EST 2000


db3l at fitlinxx.com (David Bolen) wrote in 
<uu29u2f8d.fsf at ctwd0143.fitlinxx.com>:

>speed@?.com (Jake Speed) writes:
>
>> If you just use popen(cmd, "r"), won't it take stdin from the console?
>> I suppose you could use "echo | sqlplus user/pass @file"...
>> ...or "rem | sqlplus user/pass @file" for Windows.
>
>No, if you just used os.popen() then there is no stdin for the child
>process (e.g., no file handle is opened).  In fact, occasionally some
>processes don't like this if they're written to assume they can make
>some calls against stdin before they generate their output.
>

I just did this:

import sys, os
p = os.popen("sqlplus scott/tiger @nosuchfile")
print p.readlines()
p.close()
sys.exit()

..and it hangs, with or without readlines.  'truss -f' shows
that sqlplus is blocking on 'read(0, ...)'.  When I type 'exit'
at the console, the process shows 'read(0, " e x i t\n", 1024)' 
and exits. When the command is changed to "echo | sqlplus ...", 
the read returns 0 and sqlplus exits.

-Speed!



More information about the Python-list mailing list