1

I know others have asked similar questions to this, but what I want to know is whether or not there is a way to simply open a cmd window (on windows 10), leave it open and have a python script automatically type into it.

What I actually need to do is SSH into a remote computer and then from that remote computer, run IDL commands. I have not found a way to do this with subprocess Popen or with Paramiko to SSH. In the case of subprocess, I can't get past authentication to get into the host, i.e. I can't figure out how to type a password in. With Paramiko I am able to get into the remote computer but once there I can't get my IDL code to run, and if it does run it just hangs on that command and won't output anything, even after closing.

It seems to me that rather than sending commands directly to cmd through a subprocess or os command, it would make it much easier if I could just send a string to an open cmd window and have it execute the command and read the result. I'm going through a remote computer and then running IDL code on that remote computer so there are two layers that python has to get through. If I could just write in the cmd terminal it would make my life much easier, rudimentary as it is.

Apologies if I don't have the right lingo with all of this, I'm definitely not a network programmer.

Below is my attempt to use Paramiko. The "ls" command works and the contents of the folder I'm in are printed so I know I've accessed the remote computer, but my idl command does not print anything. Printing the output from the "idl" command itself just causes the program to hang there.

import paramiko

host = "<hostname>"
user = "<myusername>"
password = input("pass:")

client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=user, password=password)

_stdin, _stdout,_stderr = client.exec_command("ls", get_pty=True)
print(_stdout.read().decode())

_stdin, _stdout,_stderr = client.exec_command("idl")
_stdin, _stdout,_stderr = client.exec_command("<my command>")
print(_stdout.read().decode())
client.close()

I made much less progress with os and/or subprocess as I can't even get into the remote computer with either of those.

  • Please look on the results of the Stack Overflow search [\[python\] \[ssh\] run commands remote](https://stackoverflow.com/search?q=%5Bpython%5D+%5Bssh%5D+run+commands+remote) like [Perform commands over ssh with Python](https://stackoverflow.com/questions/3586106/). – Mofi Mar 05 '22 at 10:01
  • Does this answer your question? [Perform commands over ssh with Python](https://stackoverflow.com/questions/3586106/perform-commands-over-ssh-with-python) – Zephyr Mar 05 '22 at 11:54

0 Answers0