timing out an ssh command

Andrei Doicin Andrei.Doicin at cern.ch
Wed May 7 10:31:36 EDT 2003


I forgot to mention something fundamental, which in the interim has given me
other ideas - the fact that the ssh command is fired off using popen as in
the code below:

############################################################################
#
### Function "the_command"

def the_command():
    payload = string.join(sys.argv[1:])
    sshcmd = 'ssh -1 -o StrictHostKeyChecking=no -l root ' + payload
    output = os.popen('{ ' + sshcmd + '; } 2>&1', 'r')
<<<<<<<<<<<<<<<<<<<<<<<<<<<
    while 1:
        try:
            line = output.readlines()
            if not line: break
            else:
                command_response = string.join(line[:])
            return command_response
        except KeyboardInterrupt: print keyboard_interrupt()

############################################################################
#

So maybe there's a way to timeout something coming back from popen ...

Something else I've not thought about is threads. Hmmm ...

A






More information about the Python-list mailing list