473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

readline timeout, or end char or something.

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
0 2018

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
1
by: Joachim | last post by:
Is there a way to set a timeout for the Console.ReadLine method?
1
by: ywzhan | last post by:
Hi, I am new here. When I use sys.stdin.readline() to get input string from user, how can I set a timeout value for this operation? thank you.
3
by: PointMan | last post by:
what i know is... while ((currentStr = sr.ReadLine()) != null) { in this area, can i get next ReadLine Value of currentStr } best regard,,
1
by: Horta | last post by:
Hi folks, Sometimes, when I do an os.popen*(), the process executed by the command hangs, and the script stops forever on the readline()/ readlines() calls. I found that I can use select, but I'm...
2
by: SriBhargav | last post by:
Hi, I've a question on setting timeout on console.readline() I would like the user to input something through Console.readline() in 5 secs. If there is no input in that time, I would like to...
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.