如何在paramiko中写入stdin(从exec_command返回)?

问题描述 投票:2回答:1

我正在尝试用paramiko写一个自定义程序的stdin。这是一个最小(非)工作的例子:

〜/ 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
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.