Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SSH在shell中启动Python脚本_Python_Python 2.7_Ssh_Paramiko - Fatal编程技术网

使用SSH在shell中启动Python脚本

使用SSH在shell中启动Python脚本,python,python-2.7,ssh,paramiko,Python,Python 2.7,Ssh,Paramiko,我想用paramiko启动一个Python脚本,它连接到我的raspberry wich作为服务器。然后在连接到树莓后,它启动如下脚本(从另一台pc向arduino发送数据): 这段代码工作正常,只是为了简化,有点像原始输入 我想通过ssh自动连接到raspberry,并启动一个python脚本,该脚本将请求输入—在上面的代码中是一个常量。 我认为像打开一个新的shell,上面的脚本已经初始化了,或者类似的东西…快速回答,没有任何选项可以帮助您将密码插入ssh命令。您必须设置共享密钥对才能在没有

我想用
paramiko
启动一个Python脚本,它连接到我的raspberry wich作为服务器。然后在连接到树莓后,它启动如下脚本(从另一台pc向arduino发送数据):

这段代码工作正常,只是为了简化,有点像原始输入

我想通过ssh自动连接到raspberry,并启动一个python脚本,该脚本将请求输入—在上面的代码中是一个常量。
我认为像打开一个新的shell,上面的脚本已经初始化了,或者类似的东西…

快速回答,没有任何选项可以帮助您将密码插入ssh命令。您必须设置共享密钥对才能在没有密码提示的情况下使用ssh。在互联网上搜索可以为您提供大量答案,例如:

因此,首先,设置密钥对。然后使用普通ssh检查是否成功。最后,在python脚本中,添加一些代码来处理ssh

import tty
import sys
import termios
import serial
import os

arduino = serial.Serial('/dev/ttyUSB0' , 9600)

x = "./mjpg_streamer -i \"./input_uvc.so -d /dev/video0 -y\" -o \"./output_http.so -w ./www\""
os.system(x)


orig_settings = termios.tcgetattr(sys.stdin)

tty.setraw(sys.stdin)
x = 0
while x != chr(27): # ESC
    x=sys.stdin.read(1)[0]
    arduino.write(x)
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, orig_settings)