Skip to content

Commit 029d9d7

Browse files
author
Dan
committed
Added stdin channel to output
1 parent 3cffa3f commit 029d9d7

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

embedded_server/embedded_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
logger = logging.getLogger("embedded_server")
5959
paramiko_logger = logging.getLogger('paramiko.transport')
6060

61-
host_key = paramiko.RSAKey(filename = os.path.sep.join([os.path.dirname(__file__), 'rsa.key']))
61+
host_key = paramiko.RSAKey(filename=os.path.sep.join([
62+
os.path.dirname(__file__), 'rsa.key']))
6263

6364
class Server(paramiko.ServerInterface):
6465
def __init__(self, transport, fail_auth=False,
@@ -126,6 +127,8 @@ def check_channel_exec_request(self, channel, cmd,
126127
return True
127128

128129
def _read_response(self, channel, process):
130+
gevent.sleep(0)
131+
logger.debug("Waiting for output")
129132
for line in process.stdout:
130133
channel.send(line)
131134
process.communicate()

pssh/pssh_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ def run_command(self, *args, **kwargs):
429429
'exception' : ConnectionErrorException(
430430
"Error connecting to host '%s:%s' - %s - retry %s/%s",
431431
host, port, 'Connection refused', 3, 3)}}
432+
433+
**Using stdin**
434+
435+
::
436+
437+
output = client.run_command('read')
438+
stdin = output['localhost']['stdin']
439+
stdin.write("writing to stdin\n")
440+
stdin.flush()
441+
for line in output['localhost']['stdout']:
442+
print line
443+
444+
writing to stdin
432445
433446
"""
434447
stop_on_errors = kwargs.pop('stop_on_errors', True)

tests/test_ssh_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_ssh_agent_authentication(self):
205205
agent.add_key(USER_KEY)
206206
client = SSHClient(self.host, port=self.listen_port,
207207
agent=agent)
208-
channel, host, stdout, stderr = client.exec_command(self.fake_cmd)
208+
channel, host, stdout, stderr, stdin = client.exec_command(self.fake_cmd)
209209
output = list(stdout)
210210
stderr = list(stderr)
211211
expected = [self.fake_resp]
@@ -254,7 +254,7 @@ def test_ssh_client_utf_encoding(self):
254254
pkey=self.user_key)
255255
expected = [u'é']
256256
cmd = u"echo 'é'"
257-
channel, host, stdout, stderr = client.exec_command(cmd)
257+
channel, host, stdout, stderr, stdin = client.exec_command(cmd)
258258
output = list(stdout)
259259
self.assertEqual(expected, output,
260260
msg="Got unexpected unicode output %s - expected %s" % (
@@ -266,7 +266,7 @@ def test_ssh_client_pty(self):
266266
and that shell commands fail accordingly"""
267267
client = SSHClient(self.host, port=self.listen_port,
268268
pkey=self.user_key)
269-
channel, host, stdout, stderr = client.exec_command(self.fake_cmd, use_shell=False)
269+
channel, host, stdout, stderr, stdin = client.exec_command(self.fake_cmd, use_shell=False)
270270
output = list(stdout)
271271
stderr = list(stderr)
272272
expected = []
@@ -276,7 +276,7 @@ def test_ssh_client_pty(self):
276276
self.assertTrue(exit_code==127,
277277
msg="Expected cmd not found error code 127, got %s instead" % (
278278
exit_code,))
279-
channel, host, stdout, stderr = client.exec_command('id', use_shell=False)
279+
channel, host, stdout, stderr, stdin = client.exec_command('id', use_shell=False)
280280
output = list(stdout)
281281
exit_code = channel.recv_exit_status()
282282
self.assertTrue(output,

0 commit comments

Comments
 (0)