From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Don Libes Newsgroups: gmane.emacs.help Subject: Re: Help - Tcl/Expect Parsing Strangeness In Emacs Shell Date: 17 Aug 2004 10:32:43 -0400 Organization: National Institute of Standards and Technology Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <1092697387.756306@sj-nntpcache-3> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1092754569 7230 80.91.224.253 (17 Aug 2004 14:56:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Aug 2004 14:56:09 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 17 16:56:01 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bx5NZ-00026T-00 for ; Tue, 17 Aug 2004 16:56:01 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bx5Rj-0004ce-B2 for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Aug 2004 11:00:19 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!cyclone.socal.rr.com!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!news4 Original-Newsgroups: comp.emacs,comp.lang.tcl,gnu.emacs.help Original-Lines: 128 Original-NNTP-Posting-Host: p-233.newsdawg.com X-Newsreader: Gnus v5.6.45/XEmacs 21.1 - "Capitol Reef" Original-Xref: shelby.stanford.edu comp.emacs:85850 comp.lang.tcl:254498 gnu.emacs.help:124807 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20154 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20154 Emacs plays around with tty settings in a way that can break simplistic Expect scripts. Have you read the Expect man page - it talks about this and how to avoid it. The Expect book has a section that describes the same thing albeit in a different way. Don "Tennis Smith" writes: > Hi, > > Apologies for the wide distribution. This is in one of those grey areas > between tools so I'm not sure where it fits. I tried posting this once > before > with a "tar" file containing my test scripts, but the mailer barfed back at > me. > > The problem is that in certain circumstances, Tcl/Expect doesn't work > correctly > while in an Emacs shell. Application output that Expect is "expecting" > will not be detected. > > I ran into this while trying to parse the output of a telnet session to an > MS > Windows machine. Initially, I thought it was something wrong with the > Windows output (or with your humble programmer ;-)). But after much > debugging, I've narrowed it down to two salient facts: > > 1 - Everything works correctly on rxvt, xterm and Emacs version > 20.7.1 and earlier. > > 2 - The only environment that consistently has this occur is Emacs versions > 21.2.95.2 and later. > > Steps To Recreate: > > Below are two tiny scripts. > > The "test.exp" script spawns a task. The "datagen.tcl" script is > called in the spawned task and simply writes to the screen. The "test.exp" > then reads output from "datagen.tcl" Run the "test.exp" script with the > "datagen.tcl" script in the same directory. > > When everything is working _correctly_, you'll see two copies of command > output from "datagen.tcl", one from stdout and one printed from expect > itself. > > If run under an xterm, expect will be able to detect output and put it into > the "accum" variable (which is then printed). But, if run in a shell under > Emacs, expect will not detect the data and will put only blank lines into > the "accum" variable. > > Has anyone else seen this or know how to fix it? > > TIA, > -Tennis > > #!/bin/sh > # > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > x > set starter { ${1:+"$@"} > shift > shift > exec expect -f $0 -- ${1:+"$@"} > } > # > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > x > # > # Ive tried this test under tcsh and bash. Both have the same > # result. > # > puts ">>>>>>>>BEGIN VERSION INFO<<<<<<<<<<\ > \nTCL VERSION:\ntcl version [info tclversion]\n\ > \nEXPECT VERSION:\n[exec expect -v]\n\ > \nBASH Version:\n[exec bash --version]\n\ > \nTCSH Version:\n [exec tcsh --version]\n\ > \n>>>>>>>END VERSION INFO<<<<<<<<<<<<<<\n\n" > spawn bash > exp_send "./datagen.tcl\n" > set accum {} > expect { > -re " " { > set accum "${accum}$expect_out(buffer)" > exp_continue > } > timeout { > if {![string length $expect_out(buffer)]} { > set accum "timed out waiting for data" > } else { > set accum "${accum}\n\nFinal timeout\n" > } > } > } > puts "accum:$accum" > > # End of test.exp > > > #!/bin/sh > # > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > x > set starter { ${1:+"$@"} > shift > shift > exec expect -f $0 -- ${1:+"$@"} > } > # > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > x > puts "ipconfig\ > \n\nWindows 2000 IP Configuration\ > \n\nEthernet adapter 126 Network:\ > \n\n Connection-specific DNS Suffix . : \ > \n IP Address. . . . . . . . . . . . : 0.0.0.0\ > \n Subnet Mask . . . . . . . . . . . : 0.0.0.0\ > \n Default Gateway . . . . . . . . . : \ > \n\nEthernet adapter 172 Network:\ > \n\n Connection-specific DNS Suffix . : \ > \n IP Address. . . . . . . . . . . . : 172.19.178.242\ > \n Subnet Mask . . . . . . . . . . . : 255.255.255.0\ > \n Default Gateway . . . . . . . . . : 172.19.178.1" > # End of datagen.tcl > > -- > Remove "-remove-to-reply" to respond to my email address directly.