[Tutor] Writing a script to interact with an interactive command program

Demonic Software demonic.software at gmail.com
Tue Jun 10 00:19:06 CEST 2008


I am trying to write an interactive shell that will pipe input from one
source to a shell/program, and then return the input to that source.  I have
been trying to do this with the os.popen*, and I have not had any success in
getting this to work.  Here is a basic piece of the code that demonstrates
what I am trying to do:

# based on code from:
# start a bash shell
(cin, cout_cerror) = os.popen4("/bin/bash")

# write a command on the input pipe of the shell
print "writing ls -all!\n\n"
cin.write("ls -all")

# print the results of my command
print cout_cerror.read()

Is there something I should be doing differently to get this behavior.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080609/c55b1919/attachment.htm>

More information about the Tutor mailing list