readline timeout, or end char or something.

G

Guy

Ok this is might take some exsplaining as this is just example code,
I have a telnet server which I've created, its ment to be a a process
queue control thing.
One of the things I think that would be really useful is to be able to
use the server as a sort of cmd prompt remote control. I use the same
sort of code below
I can write a cmd to the popen2 cmd but when reading them it reads but
then
hangs on the readline there isn't a end of output char, the only way
to stop
the hanging is to exit the process
What I need is a timeout or something, any help would be good. The
first example
won't work, it hangs, but it is what I want to do. The second
example works but its not what I want to do.
I saw a couple of things when I search for a timeout, none of which I
found to work, select
which I use sometimes won't work with this, and the normal blank
output which usally works won't.

Example 1 - This what I want to do keep the input open but read the
output without it hanging.



from popen2 import popen2

output, input = popen2("cmd.exe")
input.write("dir\n")
while 1:
outline = output.readline()
if (outline!=""):
print outline
else:
break
self.input.write("dir\n")
while 1:
outline = output.readline()
if (outline!=""):
print outline
else:
break
self.input.write("exit\n")



Example 2 - Not what I want to do, but this won't hang.



from popen2 import popen2

output, input = popen2("cmd.exe")
input.write("dir\n")
input.write("exit\n")
while 1:
outline = output.readline()
if (outline!=""):
print outline
else:
break

TIA
Guy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top