【发布时间】:2018-07-11 06:59:03
【问题描述】:
我正在尝试使用 paramiko 写入自定义程序的标准输入。这是一个最小(非)工作示例:
~/stdin_to_file.py:
#! /usr/bin/python
import time, sys
f = open('/home/me/LOG','w')
while True:
sys.stdin.flush()
data = sys.stdin.read()
f.write(data+'\n\n')
f.flush()
time.sleep(0.01)
然后我在 IPython 中执行这些命令:
import paramiko
s = paramiko.client.SSHClient
s.load_system_host_keys()
s.connect('myserver')
stdin, stdout, stderr = s.exec_command('/home/me/stdin_to_file.py')
stdin.write('Hello!')
stdin.flush()
不幸的是,~/LOG 中没有出现任何内容。但是,如果我这样做了
$ ~/stdin_to_file.py < some_other_file
some_other_file 的内容出现在 ~/LOG 中。
谁能建议我哪里出错了?看来我在做合乎逻辑的事情。这些都不起作用:
stdin.channel.send('hi')
using the get_pty parameter
sending the output of cat - to stdin_to_file.py
【问题讨论】:
标签: python unix paramiko ssh-tunnel