tags:

views:

251

answers:

4

How can I run a Python program so it outputs its STDOUT and inputs its STDIN to/from a remote telnet client?

All the program does is print out text then wait for raw_input(), repeatedly. I want a remote user to use it without needing shell access. It can be single threaded/single user.

+9  A: 

On a Unix system, you can use inetd for this. It will take care of opening the network connection for you, so your program will work as-is.

Kevin Panko
i tried it with xinetd but for some reason it seemed to prevent python from writing to files. Like I could open a file for appending, which would create the file, but if I even write a "got here" right after opening the file, the file size is still 0. running the same in python directly works as expected. strange.
ʞɔıu
+4  A: 

Make the Python script into the shell for that user. (Or if that doesn't work, wrap it up in bash script or even a executable).

(You might have to put it in /etc/shells (or equiv.))

Douglas Leeder
+2  A: 

If you don't need full telnet functionality, you can just use a socket.

Check out the Socket Server module in the standard python library. It'll enable you to easily write a program that'll listen on a port for input/output.

It won't support the proper telnet protocol negotiation, but you might not need that for what you're doing.

McPherrinM
A: 

You can just create a new linux user and set their shell to your script.

Then when they telnet in and enter the username/password, the program runs instead of bash or whatever the default shell is.