简体   繁体   中英

How to run the echo command in Python Paramiko

I need do run the echo command in the python paramiko.client.SSHClient() For this can I import any libraries. I tried paramiko.transport also not working.

After creating a SSHClient object use the exec_command method to dispatch a command to the client, eg

client = paramiko.SSHClient()
... # set client object as needed and connect to SSHClient
command = "ls -l"  # or echo
# execute command and handle output
stdin, stdout, stderr = client.exec_command(command)
print(stdout.read().decode("utf-8"))
print(f"status_code={stdout.channel.recv_exit_status()}")
print(stderr.read().decode("utf-8"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM