473,513 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pexpect echoes twice for each read

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
# Automatic scp to remote host
# Input 1 : filename
# Input 2 : destination folder
# Input 3 : hostname

import pexpect
import sys,re

ssh_cmd = "ssh " + sys.argv[3]
ssh_handle = pexpect.spawn (ssh_cmd)
ssh_handle.logfile = sys.stdout
PROMPT = "\$\ $"

try:
ssh_handle.expect(PROMPT)

ssh_handle.sendline ("scp "+ sys.argv[1] +" ro**@192.168.1.254:" +
sys.argv[2] )

ssh_handle.expect("password:")

ssh_handle.sendline(" ")

ssh_handle.expect(PROMPT)

except pexpect.TIMEOUT:
ssh_handle.logfile.write("\n Pexpect timeout !!\n")
sys.exit(1)
except KeyboardInterrupt:
ssh_handle.logfile.write("\n User interrupt!\n")
sys.exit(2)
ssh_handle.close()

Output:
-----------
$ python pexpect_test.py replace_line_break.sh /tmp/ 10.5.254.18
Last login: Tue Sep 9 15:45:05 2008 from sriram-macbook.dhcp.2wire.com
$ scp replace_line_break.sh ro**@192.168.1.254:/tmp/
scp replace_line_break.sh ro**@192.168.1.254:/tmp/
ro**@192.168.1.254's password:

replace_line_break.sh 100% 296 0.3KB/s 00:00
$ $
Sep 9 '08 #1
1 4734
On Sep 9, 4:01 pm, "Sriram Rajan" <rajan.sri...@gmail.comwrote:
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
# Automatic scp to remote host
# Input 1 : filename
# Input 2 : destination folder
# Input 3 : hostname

import pexpect
import sys,re

ssh_cmd = "ssh " + sys.argv[3]
ssh_handle = pexpect.spawn (ssh_cmd)
ssh_handle.logfile = sys.stdout
PROMPT = "\$\ $"

try:
ssh_handle.expect(PROMPT)

ssh_handle.sendline ("scp "+ sys.argv[1] +" r...@192.168.1.254:" +
sys.argv[2] )

ssh_handle.expect("password:")

ssh_handle.sendline(" ")

ssh_handle.expect(PROMPT)

except pexpect.TIMEOUT:
ssh_handle.logfile.write("\n Pexpect timeout !!\n")
sys.exit(1)
except KeyboardInterrupt:
ssh_handle.logfile.write("\n User interrupt!\n")
sys.exit(2)
ssh_handle.close()

Output:
-----------
$ python pexpect_test.py replace_line_break.sh /tmp/ 10.5.254.18
Last login: Tue Sep 9 15:45:05 2008 from sriram-macbook.dhcp.2wire.com
$ scp replace_line_break.sh r...@192.168.1.254:/tmp/
scp replace_line_break.sh r...@192.168.1.254:/tmp/
r...@192.168.1.254's password:

replace_line_break.sh 100% 296 0.3KB/s 00:00
$ $
Hi,

I had this issue as well. To correct it I upgraded to pexpect 2.3 from
2.1 and changed the following:

OLD: ssh_handle.logfile = sys.stdout
NEW: ssh_handle.logfile_read = sys.stdout

This eliminated the double display of characters as only the
characters being sent back from the device are displayed.

Let me know if this works for you.

- Darrel
Sep 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3031
by: DDE | last post by:
Hi, I have defined he following class: public class ContactInfo { public string con_nom; public string con_prenom; public string con_fonction; public string con_email; }
0
942
by: Jim Heavey | last post by:
Why does the method for on_ItemCommand fire twice when I press a button contained within my grid? My dgTask_ItemCommand which is the procedure name assigned to the "on_ItemCommand" fires twice...
8
2751
by: TS | last post by:
Hi, i have inherited a page from another user. The page is the target frame in a frameset. for some reason the whole page runs twice (page_load, init, etc. all run twice) I can't figure out how...
1
1941
by: Joey | last post by:
I am currently working on a (file-system) website in C# in VS2005. I am programming counters for the different webpages. I wrote a class and enum with functionalities exposed like... ...
4
4497
by: Henry | last post by:
for the following code snippet: int k; char c; while (true) { k = Console.Read (); if (k == -1) break; c = (char) k; Console.WriteLine ("Echo: {0}", c);
3
1471
by: VB Programmer | last post by:
Using ASP.NET 2.0... My GridView is partially defined as such.... <asp:GridView ID="CartGrid" AutoGenerateColumns="False" DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"...
9
24759
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
3
8825
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive...
7
3018
by: bowlderster | last post by:
Hello, all. This is the text file named test.txt. 1041 1467 7334 9500 2169 7724 3478 3358 9962 7464 6705 2145 6281 8827 1961 1491 3995 3942 5827 6436 6391 6604 4902 1153 1292 4382 9421 1716...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.