Help with Popen3 objects and ssh... Python 2.x

Gilles Lenfant glenfant.nospam at bigfoot.com
Wed Apr 18 16:22:25 EDT 2001


Hi,

I need to run and get the result of a command on a remote server through an
ssh client.
I can't find the way to send the password to the server.
But I'm always asked interactively for the password through the console
despite I write the "sh.tochild.write(passwd)"

Please help !

server = 'myserver'
user = 'myself'
passwd = 'mysecret'
command = 'ls -la'

import popen2
def rmtCmd(acmd):
    ''''builds a string suited to execute a command through ssh'''
    global user, server
    return 'ssh -l %s %s %s' % (user, server, acmd)

sh = popen2.Popen3('')

if __name__ == '__main__':
    # Tests stuffs
    rcmd = rmtCmd(command)
    sh = popen2.Popen3(rcmd)
    sh.tochild.write(passwd)
    sh.wait()
    print sh.fromchild.read()

I've tried other combinations to get it working... desperately !






More information about the Python-list mailing list