473,614 Members | 2,089 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.logf ile = sys.stdout
PROMPT = "\$\ $"

try:
ssh_handle.expe ct(PROMPT)

ssh_handle.send line ("scp "+ sys.argv[1] +" ro**@192.168.1. 254:" +
sys.argv[2] )

ssh_handle.expe ct("password:" )

ssh_handle.send line(" ")

ssh_handle.expe ct(PROMPT)

except pexpect.TIMEOUT :
ssh_handle.logf ile.write("\n Pexpect timeout !!\n")
sys.exit(1)
except KeyboardInterru pt:
ssh_handle.logf ile.write("\n User interrupt!\n")
sys.exit(2)
ssh_handle.clos e()

Output:
-----------
$ python pexpect_test.py replace_line_br eak.sh /tmp/ 10.5.254.18
Last login: Tue Sep 9 15:45:05 2008 from sriram-macbook.dhcp.2w ire.com
$ scp replace_line_br eak.sh ro**@192.168.1. 254:/tmp/
scp replace_line_br eak.sh ro**@192.168.1. 254:/tmp/
ro**@192.168.1. 254's password:

replace_line_br eak.sh 100% 296 0.3KB/s 00:00
$ $
Sep 9 '08 #1
1 4747
On Sep 9, 4:01 pm, "Sriram Rajan" <rajan.sri...@g mail.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.logf ile = sys.stdout
PROMPT = "\$\ $"

try:
ssh_handle.expe ct(PROMPT)

ssh_handle.send line ("scp "+ sys.argv[1] +" r...@192.168.1. 254:" +
sys.argv[2] )

ssh_handle.expe ct("password:" )

ssh_handle.send line(" ")

ssh_handle.expe ct(PROMPT)

except pexpect.TIMEOUT :
ssh_handle.logf ile.write("\n Pexpect timeout !!\n")
sys.exit(1)
except KeyboardInterru pt:
ssh_handle.logf ile.write("\n User interrupt!\n")
sys.exit(2)
ssh_handle.clos e()

Output:
-----------
$ python pexpect_test.py replace_line_br eak.sh /tmp/ 10.5.254.18
Last login: Tue Sep 9 15:45:05 2008 from sriram-macbook.dhcp.2w ire.com
$ scp replace_line_br eak.sh r...@192.168.1. 254:/tmp/
scp replace_line_br eak.sh r...@192.168.1. 254:/tmp/
r...@192.168.1. 254's password:

replace_line_br eak.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.logf ile = sys.stdout
NEW: ssh_handle.logf ile_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
3034
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
943
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 each and every time I press the button or link. Why? I have a datagrid in which I have and column defined as follows: <asp:ButtonColumn Text="Edit" HeaderText="Edit" CommandName="EditTask"></asp:ButtonColumn>
8
2755
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 this is happening. there are no transfers or redirects that are occurring in the pages. the page runs thru all of its events then starts all over again. Trying to inspect the stack track doesn't help because when i get to the init the 2nd time,...
1
1953
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... Counter.Hit(PageCounter.Home) ....and then I put it in the Page_Load section and within the if(!Page.IsPostBack) block on my web form. I can see that during debugging that the !Page.IsPostBack block fires
4
4501
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
1477
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" CellPadding="4" runat="Server" ForeColor="Gray" GridLines="None" Width="90%" BorderStyle="Inset" BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
9
24783
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 page life cycle. In this example the event fires twice when a) GridView EnableViewState=False and any image type control in the <columns/> element. When either EnableViewState is set to true or the image button is removed, the event fires once....
3
8840
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 one call to my handler? I'm using the most basic wiring as it comes out of VS 2005.. Thanks in advance for your help! ex/ <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
7
3033
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 2718 2895 I wanna to read the data to an array, as the follows:
0
8130
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8279
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7093
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6088
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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 we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.