popen, Pipes with programs that expect user input
omniflex at mail.ru
Mon Jan 8 17:06:54 CET 2007
I am writing a terminal server client-server application, that offers
the client the ability to run commands on the server and read their
So far everything works fine, but I encounter a problem with commands
which require some sort of user input; i.e. they don't return
This is my setup:
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
"""Executes a command and returns a tuple (stdin,
outErrFile, inFile = os.popen4(command)
return (inFile, outErrFile)
fouterr, fin = myExecEx('date') # try 'date /t' as well
print "an exception occurred"
On Windows, the 'date' command will show the current date, and then
prompt me to enter a new one (thus waiting for something to come to
I am reading the output with:
but data is empty (also, I must mention that "an exception occurred"
is not shown)
If I execute
(the /t parameter tells the date tool that it has to print the current
date and not wait for user input), then the program works as
Also, I noticed that if I uncomment the line in which I wrote to
then I can read STDOUT without problems (but this is counter-intuitive
to me; I don't know what to write to STDIN before I see what STDOUT
has to say).
I have tried other commands from the popen family, but in either case
the behaviour was the same.
Could someone point out the cause of this? It seems to me that the
interpreter is stuck at this line
and it won't go forward unless popen returns. If so, how should the
objective be achieved?
More information about the Python-list