473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 10585
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Surette | last post by:
I have been trying to automate the changing of passwords using python and pexpect. I wrote a script as a test and it works, except that it gives me an exception when it stops running: Exception...
2
by: Adrian Casey | last post by:
I have a collection of tcl expect scripts which I am converting to python using the excellent pexpect module (http://pexpect.sourceforge.net/). So far I've had great success in getting all my...
3
by: Maurice LING | last post by:
I know this might sounds wierd but I'm wondering if I can use pexpect or os.popen3 function to invoke and control python interpreter to make it act like a python interpreter in python? maurice
1
by: Baillargeon, Sonny | last post by:
I am trying to use a pexpect script using python v2.3.4 with pexpect module .999 on Solaris 8. I try to execute this script. #!/usr/bin/env python '''This runs "ls -l" on a remote host using...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
0
by: Salvatore Iovene | last post by:
Hi, I'm using the pexpect module to spawn some processes in a testing environment. pexpect uses, internally, os.execv. What I need to do is valgrind python and get memory leaks from the spawned...
0
by: loorthu | last post by:
I am noticing that pexpect kills any child that it is spawned when the parent is terminated using SIGINT (e.g Ctrl-C on the shell), but not when it is killed by SIGKILL (e.g 'kill -9' on the parent...
1
by: Sriram Rajan | last post by:
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 #...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.