LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   python: pexpect problems? (http://www.linuxquestions.org/questions/programming-9/python-pexpect-problems-421138/)

Chowroc 03-02-2006 11:08 PM

python: pexpect problems?
 
I tried pexpect package to excute ssh, but get the exception, what is wrong?

Code:

>>> foo = pexpect.spawn('scp root@192.168.126.11:/root/expect-5.42.1-1.i386.rpm /tmp')
>>> foo.logfile = sys.stdout
>>> foo.expect('.*password:')
root@192.168.126.11's password: 0
>>> foo.sendline('symqfct')
symqfct
8
>>> foo.interact()


expect-5.42.1-1.i386.rpm 100% 148KB 147.7KB/s 00:00

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/site-packages/pexpect.py", line 1062, in interact
self.__interact_copy(escape_character)
File "/usr/lib/python2.3/site-packages/pexpect.py", line 1086, in __interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.3/site-packages/pexpect.py", line 1075, in __interact_read
return os.read(fd, 1000)
OSError: [Errno 5] Input/output error

And I want to do something more complicated, like this:
Code:

>>> cmd = 'ssh %s@%s "cd %s; find . | grep %s.*%s.*%s >tmplist; tar -T tmplist -P -c -z -f -" | tar -C %s -x -z -f -' % (user, host, src, zone, FILE, strTime, dst)
>>> print cmd
ssh monitor@192.168.1.14 "cd /home/monitor; find . | grep QBO5.*objscenesserver.*060302 >tmplist; tar -T tmplist -P -c -z -f -" | tar -C /tmp/obj -x -z -f -
>>> import pexpect
>>> ssh = pexpect.spawn(cmd)
>>> ssh.expect('.*password:')
0
>>> ssh.sendline(passwd)
16
>>> ssh.interact()

The exception continues and I can't find the files in /tmp/obj, but if I run it in the shell, it does:
Code:

sh# ssh monitor@192.168.1.14 "cd /home/monitor; find . | grep QBO5.*objscenesserver.*060302 >tmplist; tar -T tmplist -P -c -z -f -" | tar -C /tmp/obj -x -z -f -
This print the gziped content the the standard input:
Code:

# ssh monitor@192.168.1.14 "cd /home/monitor; find . | grep QBO5.*objscenesserver.*060302 >tmplist; tar -T tmplist -P -c -z -f -"
and pexpect also done this, so "| tar -C /tmp/obj -x -z -f -" takes no effect when using pexpect package. Why?

Thanks.


All times are GMT -5. The time now is 11:21 AM.