By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

readline timeout, or end char or something.

P: n/a
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
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.