我正在使用一个使用 localhost 连接到远程 pc 的机器人。我使用 Paramiko 库将命令从远程 pc 发送到我的机器人。我想在/activate 主题上发布一个数字,如下所示:
rostopic pub /activate std_msgs/Int16 "data: 1"
问题不在于我的连接,因为上述命令使用 PuTTY 或 SSH 工作。我写了以下代码:
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)
但是使用此代码,我在我的机器人中看不到任何结果。任何人都可以帮忙吗?
最佳答案
如果您在执行命令时遇到问题,您需要阅读它们的(错误)输出以查看任何错误消息。
见 Wait to finish command executed with Python Paramiko
关于python - 使用 Paramiko 在远程机器上执行命令无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68083651/