簡體   English   中英

subprocess.Popen()讀取文件

[英]subprocess.Popen() read a file

我正在嘗試使用子進程讀取存儲在遠程服務器中的文件。

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

此錯誤是否表示找不到服務器上的文件? 還是子過程中有錯誤? Google對這個錯誤的幫助並不大。

我也使用未在此處指定的代理服務器,這可能是個問題嗎?

干杯,

我想Windows無法找到SSH可執行文件。 檢查在cmd.exe鍵入ssh時會發生什么。 嘗試在Popen調用中為SSH客戶端可執行文件添加完整路徑,或將SSH的目錄添加到PATH環境變量中。

似乎無法解決“ ssh”。 我可以完全限定Popen構造函數調用中ssh可執行文件的位置和/或它位於可搜索的PATH中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM