473,288 Members | 1,771 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,288 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 10581
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.