How to send EOF to stdin in paramiko?

Posted by Alexandru on Stack Overflow See other posts from Stack Overflow or by Alexandru
Published on 2010-03-31T15:36:00Z Indexed on 2010/03/31 15:43 UTC
Read the original article Hit count: 390

Filed under:
|
|
|

I would like to execute some program through ssh and redirect its input from a file. The behaviour of the following code:

channel.exec_command('cat')
with open('mumu', 'r') as f:
    text = f.read()
    nbytes = 0
    while nbytes < len(text):
        sent = channel.send(text[nbytes:])
        if sent == 0:
            break
        nbytes += sent

should be equivalent to (assuming public-key authentication):

 ssh user@host cat < mumu

However the application hangs waiting for more input. I think this happens because the stdin stream is never closed. How do I do that?

© Stack Overflow or respective owner

Related posts about python

Related posts about paramiko