readline timeout, or end char or something.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guy

    readline timeout, or end char or something.

    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("di r\n")
    while 1:
    outline = output.readline ()
    if (outline!=""):
    print outline
    else:
    break
    self.input.writ e("dir\n")
    while 1:
    outline = output.readline ()
    if (outline!=""):
    print outline
    else:
    break
    self.input.writ e("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("di r\n")
    input.write("ex it\n")
    while 1:
    outline = output.readline ()
    if (outline!=""):
    print outline
    else:
    break

    TIA
    Guy
Working...