Wednesday, 15 August 2012

ssh session as python subprocess takes input but does not print it to stdout -


I am trying to use Python's CMD library to create a shell with limited commands. One requirement I should be able to run an order that executes an existing shell script which opens an ssh session on the remote machine and allows the user to interact with the remote shell, as if it is a regular ssh The session was.

Just by using subprocess. Popen ('[/ path / to / connect.sh]') works well as well as the starting point in addition to at least one issue. You can interact with the remote shell but the input you typed is not shown at stdout ... so for example you see the prompt on your standout, but when you type 'ls' you do not type it But when you hit the hit it works as expected.

I am trying to wrap my head about how to print input in stdout and still send it to remote SSP session.

Edit: The code was just one line without using the actual CDD:

ssh_session = subprocess.Popen (['connect.sh'])

It was removed from a class of a do_ * method, extended CMD. CMD I think I may end up using paramiko but will still be interested in anyone's input on it. Suppose you are using a system like Unix, SSH detects whether you are on the terminal or not? When it will detect that you are not on the terminal, such as using subprocess, it will not echo the typed characters. Instead, you want to use a pseudo-terminal, you can see or in this way you can get output from SSH as if it is running on the correct terminal.


No comments:

Post a Comment