Search code examples
pythonubuntusshrosparamiko

Executing command on remote machine using Paramiko has no effect


I am using a robot that is connected to a remote pc using localhost. I have used the Paramiko library to send commands from remote pc to my robot. I want to publish a number on /activate topic like this:

rostopic pub /activate std_msgs/Int16 "data: 1"

The problem is not my connection because the above command works using PuTTY or SSH.

I have written the following code:

import paramiko
host = "xxx.xxx.x.x"
port = 22
username = "robot"
password = "xxx"
command = "rostopic pub /activate std_msgs/Int16 'data: 1'"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
stdin, stdout, stderr = ssh.exec_command(command)

But using this code, I see no results in my robot. Can anyone help?


Solution

  • If you have problems with executing commands, you need to read their (error) output to see any error messages.