[Twisted-Python] Execute interactive commands with a custom ssh shell
![](https://secure.gravatar.com/avatar/1ce2d65062aa6fb902e96308d3f8886e.jpg?s=120&d=mm&r=g)
Hello all, I try to implement a custom ssh server with twisted . I use* sshserver.py to begin (* http://www.devshed.com/c/a/Python/SSH-with-Twisted/ ) I would like to execute interactive scripts which are on my server. The problem is theses scripts are interactives. How can I redirect IO on my shell ? For example, if I want to install a software with apt. I have questions to install dependencies ( yes/no) I start to create a definition for this function like def do_apt. And then when in my custom shell I execute ( apt python)., that executes apt-get install python on the server. But how can I redirect the output in my shell to answer dependencies questions ? Thanks for your help Best Regards The Noob06
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Sat, 16 Aug 2008 14:04:22 +0200, The Noob <thenoob06@gmail.com> wrote:
Hello all, I try to implement a custom ssh server with twisted . I use* sshserver.py to begin (* http://www.devshed.com/c/a/Python/SSH-with-Twisted/ ) I would like to execute interactive scripts which are on my server. The problem is theses scripts are interactives. How can I redirect IO on my shell ? For example, if I want to install a software with apt. I have questions to install dependencies ( yes/no) I start to create a definition for this function like def do_apt. And then when in my custom shell I execute ( apt python)., that executes apt-get install python on the server. But how can I redirect the output in my shell to answer dependencies questions ? Thanks for your help
To run a program like apt, you must be using `reactor.spawnProcess´. That means that you have two different protocol implementations. One to talk to the SSH connection (eg, `SSHDemoProtocol´ in the O'Reilly example) and one to talk to the child process. If you want output from the child process to show up in the SSH client, then when the process protocol receives data from it, it should pass it on to the SSH protocol to write to the client. Similarly, if you want input from the SSH client written to the stdin of the child process, when the SSH protocol receives data it should pass it on to the process protocol to write to the child process. You'll have to keep track of what state your application is in to do this correctly. Input should only be handled this way when there is actually a child process running. Jean-Paul
![](https://secure.gravatar.com/avatar/1ce2d65062aa6fb902e96308d3f8886e.jpg?s=120&d=mm&r=g)
Thanks very much Jean-Paul for your answer. I will try to implement reactor.spawnProcess with this example. Best Regards TheNoob06 2008/8/16 Jean-Paul Calderone <exarkun@divmod.com>
On Sat, 16 Aug 2008 14:04:22 +0200, The Noob <thenoob06@gmail.com> wrote:
Hello all, I try to implement a custom ssh server with twisted . I use* sshserver.py to begin (* http://www.devshed.com/c/a/Python/SSH-with-Twisted/ ) I would like to execute interactive scripts which are on my server. The problem is theses scripts are interactives. How can I redirect IO on my shell ? For example, if I want to install a software with apt. I have questions to install dependencies ( yes/no) I start to create a definition for this function like def do_apt. And then when in my custom shell I execute ( apt python)., that executes apt-get install python on the server. But how can I redirect the output in my shell to answer dependencies questions ? Thanks for your help
To run a program like apt, you must be using `reactor.spawnProcess´. That means that you have two different protocol implementations. One to talk to the SSH connection (eg, `SSHDemoProtocol´ in the O'Reilly example) and one to talk to the child process.
If you want output from the child process to show up in the SSH client, then when the process protocol receives data from it, it should pass it on to the SSH protocol to write to the client. Similarly, if you want input from the SSH client written to the stdin of the child process, when the SSH protocol receives data it should pass it on to the process protocol to write to the child process.
You'll have to keep track of what state your application is in to do this correctly. Input should only be handled this way when there is actually a child process running.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (2)
-
Jean-Paul Calderone
-
The Noob