Home/Support/Support Forum/how to check for input on telnet (stdio) from python script
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

how to check for input on telnet (stdio) from python script

0 votes
I am trying a way to check for keyboard input during an interactive telnet session on a connectport X so basically i go:

#> py myscript.py

I can ask for user input with the following code (this works):

command = ""
console = code.InteractiveConsole()
while command != "exit":
command = console.raw_input("what do you want (or type “exit” to quit) $ ")
command = command.strip()
handle_command(command)

my problem is console.raw_input() is blocking, which i do not want.

the normal "Python" way of solving is by using the select function on stdio:

rlist, _, _ = select([sys.stdin], [], [], timeout)
if rlist:
s = sys.stdin.readline()
print s
else:
print "No input. Moving on..."

but unfortunately when i try this Python on the CPX gives me an exception telling me sys.stdin has no method "fileno"

Is there a way to solve this problem?
asked Jun 3, 2013 in Python by raoulvb New to the Community (14 points)

Please log in or register to answer this question.

1 Answer

0 votes
Threading is your answer. There is no fileno to latch onto with select, you'll need to have a thread monitor/respond to user input, and have a secondary thread do whatever else you need it to do.
answered Jun 3, 2013 by charliek Veteran of the Digi Community (408 points)
Thanks Charlie, i guessed this would be the answer i would get, but honestly was hoping to avoid threading for my simple application.
...