使用ssh命令时,subprocess.Popen shell = True to shell = False

时间:2017-12-13 12:22:01

标签: python raspberry-pi

我有命令:

proc = subprocess.Popen(["sshpass -p root ssh root@(IP_ADRESS) 'cd
/home/pi/reed && python reed.py'"],  shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, )

shell=True很危险,所以我想避开它并使用shell=False

任何提示?

2 个答案:

答案 0 :(得分:0)

您应该拆分命令。像这样:

proc = subprocess.Popen("sshpass -p root ssh root@(IP_ADRESS) 'cd /home/pi/reed && python reed.py'".split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, )

答案 1 :(得分:0)

也许这个?

proc = subprocess.Popen(["sshpass", "-p", "root", "ssh", "root@(IP_ADRESS)", "cd /home/pi/reed && python reed.py"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, )