LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-02-2006, 11:08 PM   #1
Chowroc
Member
 
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?

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.
 
  


Reply


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


All times are GMT -5. The time now is 01:18 PM.

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