471,330 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Problem with PEXPECT in Python

Hello,

I am attempting to use pexpect in python to copy files from a server
using scp; the copy works however exceptions are thrown and it exits
unsuccessfully. Below is the a sample code and the error:

#Begin Code

import sys
import pexpect

def GetServerData(self):
foo = pexpect.spawn('scp us**@server.com:/home/config/
role{/file1,/files/file2,/files/file3} /tmp')
foo.expect('.*password:*')
foo.sendline('server_password')
foo.interact()

#End Code

#Begin Output

file1 100% 10KB 10.0KB/s
00:01
file2 100% 946 0.9KB/s
00:00
file3 100% 1655 1.6KB/s
00:00
Traceback (most recent call last):
File "mygui.py", line 6, in ?
f = Form1()
File "/home/Kevin/form1.py", line 41, in __init__
self.GetServerData()
File "/home/Kevin/form1.py", line 84, in GetServerData
foo.interact()
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1062, in
interact
selfw.__interact_copy(escape_character)
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1086, in
__interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1075, in
__interact_read
return os.read(fd, 1000)
OSError: [Errno 5] Input/output error

#End Output

The problem seems to be with the call foo.interact(); does anyone know
how to fix this? Any help will be much appreciated.

Jul 1 '07 #1
1 10229
On Jun 30, 5:50 pm, Kevin Erickson <kevin.erick...@gmail.comwrote:
Hello,

I am attempting to use pexpect in python to copy files from a server
using scp; the copy works however exceptions are thrown and it exits
unsuccessfully. Below is the a sample code and the error:

#Begin Code

import sys
import pexpect

def GetServerData(self):
foo = pexpect.spawn('scp u...@server.com:/home/config/
role{/file1,/files/file2,/files/file3} /tmp')
foo.expect('.*password:*')
foo.sendline('server_password')
foo.interact()

#End Code

#Begin Output

file1 100% 10KB 10.0KB/s
00:01
file2 100% 946 0.9KB/s
00:00
file3 100% 1655 1.6KB/s
00:00
Traceback (most recent call last):
File "mygui.py", line 6, in ?
f = Form1()
File "/home/Kevin/form1.py", line 41, in __init__
self.GetServerData()
File "/home/Kevin/form1.py", line 84, in GetServerData
foo.interact()
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1062, in
interact
selfw.__interact_copy(escape_character)
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1086, in
__interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.4/site-packages/pexpect.py", line 1075, in
__interact_read
return os.read(fd, 1000)
OSError: [Errno 5] Input/output error

#End Output

The problem seems to be with the call foo.interact(); does anyone know
how to fix this? Any help will be much appreciated.

I have found a work around for my problem. I replace the following
line:

foo.interact()
with
foo.expect(pexpect.EOF)

That change gets rid of the errors and works great for copying the
files down from the server.

Kevin

Jul 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael Surette | last post: by
2 posts views Thread by Adrian Casey | last post: by
3 posts views Thread by Maurice LING | last post: by
1 post views Thread by Baillargeon, Sonny | last post: by
5 posts views Thread by half.italian | last post: by
reply views Thread by Salvatore Iovene | last post: by
reply views Thread by loorthu | last post: by
1 post views Thread by Sriram Rajan | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.