I’m trying to write a Client/Server using Twisted that will allow the client to issue remote commands on the server and receive response data in real time. i.e. If I run $> ssh server someProg.sh, I will see the results in ‘real time’, not all at once when the process finishes. Is this sort of thing possible in Twisted? Thanks.
I’m trying to write a Client/Server using Twisted that will allow the client to
Share
Absolutely. As already noted in a comment, you can do this by connecting to the SSH server directly with Twisted’s “conch” library. This is more scalable (you can open lots of connections without any extra processes) and more portable (it can work on Windows) but it won’t take into account your OpenSSH configuration, and you have to write a bunch of additional code to deal with things like host key verification. The other question doesn’t directly address your main question here, either, which is about the output being processed as it arrives.
The simple answer is “yes”, but here’s a demonstration program that spawns several subprocesses and displays their output as it goes. You can replace the
sys.executablewith another program to spawn (i.e.ssh) and it’ll work exactly the same way.