For some reason, Using pexpect causes my output to echo twice when I
connect from my MAC Darwin (10.4) to Linux (CentOS release 5 ):

The program:
---------------------
#!/usr/bin/python
# Automatic scp to remote host
# Input 1 : filename
# Input 2 : destination folder
# Input 3 : hostname

import pexpect
import sys,re

ssh_cmd = "ssh " + sys.argv[3]
ssh_handle = pexpect.spawn (ssh_cmd)
ssh_handle.logfile = sys.stdout
PROMPT = "\$\ $"

try:
  ssh_handle.expect(PROMPT)

  ssh_handle.sendline ("scp "+ sys.argv[1] +" [EMAIL PROTECTED]:" +
sys.argv[2] )

  ssh_handle.expect("password:")

  ssh_handle.sendline(" ")

  ssh_handle.expect(PROMPT)

except pexpect.TIMEOUT:
    ssh_handle.logfile.write("\n Pexpect timeout !!\n")
    sys.exit(1)
except KeyboardInterrupt:
    ssh_handle.logfile.write("\n User interrupt!\n")
    sys.exit(2)
ssh_handle.close()

Output:
-----------
$ python pexpect_test.py replace_line_break.sh /tmp/ 10.5.254.18
Last login: Tue Sep  9 15:45:05 2008 from sriram-macbook.dhcp.2wire.com
$ scp replace_line_break.sh [EMAIL PROTECTED]:/tmp/
scp replace_line_break.sh [EMAIL PROTECTED]:/tmp/
[EMAIL PROTECTED]'s password:

replace_line_break.sh                         100%  296     0.3KB/s   00:00
$ $
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to