Python subprocess.Popen()读取文件
我正在尝试使用子进程读取存储在远程服务器中的文件Python subprocess.Popen()读取文件,python,ssh,proxy,subprocess,Python,Ssh,Proxy,Subprocess,我正在尝试使用子进程读取存储在远程服务器中的文件 import subprocess import sys ssh = subprocess.Popen(['ssh', 'hjh:passwd@myserver', 'cat', 'data/test.txt'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE
import subprocess
import sys
ssh = subprocess.Popen(['ssh', 'hjh:passwd@myserver', 'cat', 'data/test.txt'],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
print result
现在运行此命令会导致错误
Traceback (most recent call last):
File "C:/Users/hjh/Desktop/try.py", line 15, in <module>
stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
回溯(最近一次呼叫最后一次):
文件“C:/Users/hjh/Desktop/try.py”,第15行,在
stderr=子流程(管道)
文件“C:\Python27\lib\subprocess.py”,第710行,在_init中__
错误读取,错误写入)
文件“C:\Python27\lib\subprocess.py”,第958行,在执行子进程中
startupinfo)
WindowsError:[错误2]系统找不到指定的文件
此错误是否意味着找不到服务器上的文件?或者子流程中是否存在错误?谷歌在这个错误上对我帮助不大
我还使用了一个没有在这里指定的代理,这会是一个问题吗
干杯,似乎“ssh”无法解决。我要么在Popen构造函数调用中完全限定ssh可执行文件的位置,要么它位于可搜索路径中。我想Windows无法找到ssh可执行文件。检查在
cmd.exe
中键入ssh
时发生的情况。尝试在Popen调用中向SSH客户端可执行文件添加完整路径,或将SSH的目录添加到path环境变量。是,当我更改shell=True
时,显示'SSH'未被识别为内部或外部命令
错误。所以我会解决的。谢谢