Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-02-2006, 11:08 PM   #1
Registered: Dec 2004
Posts: 145

Rep: Reputation: 15
python: pexpect problems?

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

>>> foo = pexpect.spawn('scp root@ /tmp')
>>> foo.logfile = sys.stdout
>>> foo.expect('.*password:')
root@'s password: 0
>>> foo.sendline('symqfct')
>>> 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/", line 1062, in interact
File "/usr/lib/python2.3/site-packages/", line 1086, in __interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.3/site-packages/", line 1075, in __interact_read
return, 1000)
OSError: [Errno 5] Input/output error
And I want to do something more complicated, like this:
>>> 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@ "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:')
>>> ssh.sendline(passwd)
>>> 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:
sh# ssh monitor@ "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:
# ssh monitor@ "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?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python problems in suse 9.3 giovani_78 Linux - Software 1 07-16-2005 03:24 AM
problems with Python dratix Ubuntu 3 06-15-2005 09:33 PM
problems with python: what else is new??? mrchaos Linux - Software 4 05-13-2005 02:43 PM
Python ftplib problems p-static Programming 0 08-08-2004 10:42 AM
python problems with fluxspace Tyir Linux - General 1 12-19-2003 04:51 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration