f



expect script : "expect 'X', send 'Y'" until expect "Z".

Hi.


I am having some difficulties with an expect script, and was hoping
someone could help me out here.


I am running a scripted telnet session to some 'black box' appliance,
and would like to retrieve the output of a particular command.
However, the output of the command is longer than a single screen
full. Since it was designed for interactive use, you get the magic
string "[=More (xx%)=]" after each screenfull of output, at which
point the command expects you to hit the spacebar in order to get
another screenfull of output.

Of course, I could just "send <space>" a few times, but since I have
no idea how long the output will be in advance, this does not appear
to be such a good approach. It looks like I would have to do something
were I keep sending a space as long as I keep getting/expecting the
string "[=More (xx%)=]", and stop doing that after I have
gotten/expected the prompt again. (which is "% ").

Does anyone have any idea on how to do such a thing in expect ? Of
course, other suggestions to tackle the same problem are welcome as
well of course.



Sincerely,

John Smith.
0
lbalbalba (26)
10/20/2004 11:05:52 AM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

3 Replies
1071 Views

Similar Articles

[PageSpeed] 27

"J.Smith" <lbalbalba@hotmail.com> wrote in message
news:737da4e2.0410200305.1f12696f@posting.google.com...
> Hi.
>
>
> I am having some difficulties with an expect script, and was hoping
> someone could help me out here.
>
>
> I am running a scripted telnet session to some 'black box' appliance,
> and would like to retrieve the output of a particular command.
> However, the output of the command is longer than a single screen
> full. Since it was designed for interactive use, you get the magic
> string "[=More (xx%)=]" after each screenfull of output, at which
> point the command expects you to hit the spacebar in order to get
> another screenfull of output.
>
> Of course, I could just "send <space>" a few times, but since I have
> no idea how long the output will be in advance, this does not appear
> to be such a good approach. It looks like I would have to do something
> were I keep sending a space as long as I keep getting/expecting the
> string "[=More (xx%)=]", and stop doing that after I have
> gotten/expected the prompt again. (which is "% ").
>
> Does anyone have any idea on how to do such a thing in expect ? Of
> course, other suggestions to tackle the same problem are welcome as
> well of course.
>
>
>
> Sincerely,
>
> John Smith.

I've not done *any* work with expect, but I do plan on it, so I read
postings about it all the time.  From what I have seen in some sample
programs, you can give expect multiple  match strings, so why not just:

set expectingmore 1
set moreprompt "=]"
set endprompt "% "

while (expectingmore) {
expect {
timeout {set expectingmore 0}
"$moreprompt" {send " "}
"$endprompt" {set expectingmore 0}
}
}

or, perhaps more simply:

while (1) {
expect {
timeout break
"=]" {send " "}
"% " break
}
}

tcl/expect veterans, please proofread!

Rufus


0
nospam21 (19047)
10/20/2004 2:44:42 PM
In article <1098283492.TP2TllaGGNeryKYOiJbYJQ@teranews>,
Rufus V. Smith <nospam@nospam.com> wrote:
>
>"J.Smith" <lbalbalba@hotmail.com> wrote in message
>news:737da4e2.0410200305.1f12696f@posting.google.com...
>> Hi.
>>
>>
>> I am having some difficulties with an expect script, and was hoping
>> someone could help me out here.
>>
>>
>> I am running a scripted telnet session to some 'black box' appliance,
>> and would like to retrieve the output of a particular command.
>> However, the output of the command is longer than a single screen
>> full. Since it was designed for interactive use, you get the magic
>> string "[=More (xx%)=]" after each screenfull of output, at which
>> point the command expects you to hit the spacebar in order to get
>> another screenfull of output.
>>
>> Of course, I could just "send <space>" a few times, but since I have
>> no idea how long the output will be in advance, this does not appear
>> to be such a good approach. It looks like I would have to do something
>> were I keep sending a space as long as I keep getting/expecting the
>> string "[=More (xx%)=]", and stop doing that after I have
>> gotten/expected the prompt again. (which is "% ").
>>
>> Does anyone have any idea on how to do such a thing in expect ? Of
>> course, other suggestions to tackle the same problem are welcome as
>> well of course.
>>
>>
>>
>> Sincerely,
>>
>> John Smith.
>
>I've not done *any* work with expect, but I do plan on it, so I read
>postings about it all the time.  From what I have seen in some sample
>programs, you can give expect multiple  match strings, so why not just:
>
>set expectingmore 1
>set moreprompt "=]"
>set endprompt "% "
>
>while (expectingmore) {
>expect {
>timeout {set expectingmore 0}
>"$moreprompt" {send " "}
>"$endprompt" {set expectingmore 0}
>}
>}
>
>or, perhaps more simply:
>
>while (1) {
>expect {
>timeout break
>"=]" {send " "}
>"% " break
>}
>}
>
>tcl/expect veterans, please proofread!
>
>Rufus
>
>

Nice work!  For not having worked with Expect, you sure fake it well.

A few aesthetic refinements on your suggestions are possible.  In
particular, "while 1 ..." in Expect code should make one consider 
whether a better solution will involve exp_continue.  <URL:
http://groups.google.com/groups?th=a3a4d69833cd0bed > explains more.
0
claird (2363)
10/20/2004 4:08:04 PM
"Rufus V. Smith" <nospam@nospam.com> wrote in message 
news:1098283492.TP2TllaGGNeryKYOiJbYJQ@teranews...
>
> while (1) {
> expect {
> timeout break
> "=]" {send " "}
> "% " break
> }
> }
>

Yup, that works as advertised. Thanks.


Sincerely,

John Smith. 


0
lbalbalba (26)
10/23/2004 8:15:27 AM
Reply:

Similar Artilces:

ABF "error: expected identifier or '(' before '=' token"
When trying to compile an ABF application on a Red Hat Enterprise Linux Server release 5.4,Intel(R) Xeon(R) and II 9.1.2 (int.lnx/ 100)NPTL, I get the following errors : "Processing form 'ylxo60701p' . . . Forcing compilation to create object file. Compiling '218688.c' . . . 218688.c:1420: error: expected identifier or '(' before '=' token E_AB001E Compilation failed" I've found out that the form in question (218688.c) is missing the global FRAME identifier here : FRAME * = { &_form0 }; which should be replaced wi...

Dev C++ Err "expected `]' before ';' token" / source "DWORD rtec_Stack[XYZ_SIZE] __attribute__((aligned(4)));"
In Dev C++, we tried to compile a application, but it will throw some peculiar error. please find it below "path/main.cpp expected `]' before ';' token" and the source code is "DWORD rtec_Stack[XYZ_SIZE] __attribute__((aligned(4)));" is this problem of envirnment or else? nagaraj wrote: > In Dev C++, we tried to compile a application, but it will throw some > peculiar error. please find it below > > "path/main.cpp expected `]' before ';' token" and the source code is > "DWORD rtec_Stack[XYZ_SIZE] __attribute__((align...

"Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from table order by artist", it works perfectly. However if i introduce the 'where' option, as in "select * from table where ...

'quote' to `quote'
Hi, what is the way to change 'shocking,' said Sally into `shocking', said Sally automatically as Tex read the author.txt file? Does this method also change "whatever happens," he said into ``whatever happens.'' he said. David R David R <angel_ov_north@tiscali.co.uk> wrote: > what is the way to change 'shocking,' said Sally > into `shocking', said Sally > automatically as Tex read the > author.txt file? It is possible (e.g. via an active '). But I suspect, this is a lot easier using a script language or similar. Also you should consider ['s] coming from genitive and other uses of the apostrophe. Yours sincerely Heiko <oberdiek@uni-freiburg.de> David R wrote: > what is the way to change 'shocking,' said Sally > into `shocking', said Sally > automatically as Tex read the > author.txt file? Tricky thing to do on the TeX level because you can't tell a quote from an apostrophe in a reliable and efficient way. This will probably require pre-processing of author.txt (it's no big deal with regular expressions). > Does this method also change "whatever happens," he said > into ``whatever happens.'' he said. Assuming you're using Latex: try the csquotes package. See \MakeOuterQuote{"} in the tutorial. -- Sender address blackholed; do not reply to From: address. You can still reach me by email at: plehman gmx net. On Wed, 10 Ja...

[9fans] acme and openning of ", "", '''chk' scripts (by rsc)
------=_Part_63992_24920993.1223483737771 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, is that an intention that acme does not recognize " (or "", not so sure about '''chk' ) to be a name of a valid file? At least " and "" seems to me to be a valid file name, but clicking on it with button 3 in acme doesn't work --- file is not opened. Only explicit use of Get opens it. Thanks Ruda ------=_Part_63992_24920993.1223483737771 Content-Type: text/html; charset=ISO-8859-1 Content...

[why are trailing '\n's missing in "$x"]: x="$(printf "hi\n\n")"; printf "$x"
Ex ~ $ printf "hi\n\n"|cat -A hi$ $ ~ $ x="$(printf "hi\n\n")" ~ $ printf "$x"|cat -A hi~ $ Why are the trailing '\n's not in "$x"? Is there any way to stop this, w/o using a tempfile? -- thanks! On 12/29/2013 11:34 PM, Name withheld by request wrote: > x="$(printf "hi\n\n")" x="$(printf "%s" "hi\n\n")" Best regards, Cyrus In article <bibnk6Ftcm6U1@mid.individual.net>, Cyrus Kriticos <cyrus.kriticos@googlemail.com> wrote: >On 12/29/2013 11:34 PM, Name withheld by request wrote: >> x="$(printf "hi\n\n")" > >x="$(printf "%s" "hi\n\n")" > >Best regards, >Cyrus Which is, at best, a pedantic nitpick, having nothing to do with OP's problem. In fact, ITYM: x="$(printf "%s\n\n" "hi")" (which still doesn't solve OP's problem, but at least demonstrates better pedantry) -- Watching ConservaLoons playing with statistics and facts is like watching a newborn play with a computer. Endlessly amusing, but totally unproductive. On 12/30/2013 12:00 AM, Kenny McCormack wrote: > In article <bibnk6Ftcm6U1@mid.individual.net>, > Cyrus Kriticos <cyrus.kriticos@googlemail.com> wrote: >> On 12/29/2013 11:34 PM, Name withheld by request wrote: >>> x="...

(mapcar 'quote '("1" "2" "3" "4"))
(mapcar 'quote '("1" "2" "3" "4")) returns ((quote "4") (quote "4") (quote "4") (quote "4")) Interesting and (for me) unexpected. Because (mapcar 'read '("1" "2" "3" "4")) returns (1 2 3 4) and (mapcar 'princ '("1" "2" "3" "4")) gives 1234("1" "2" "3" "4") Why isn't (mapcar 'quote '("1" "2" "3" "4")) returning ((quote "1") (quote "2") (quote "3") (quote "4")) Tom Haws www.hawsedc.com Probably has to do with the fact that 'arg and (quote arg) are equivalent, and LISP gets confused by the construct 'quote, which is about the same as (quote (quote arg)). But I don't pretend to know all of the mechanics of the error; the results are somewhat different in R14, BTW: Command: (mapcar 'quote '("1" "2" "3" "4")) ((<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4") (<Subr: #22e3e40> "4")) ___ "Tom Haws" <hawstom@despammed.com> wrote in message news:77317472.0309160733.45ea9d8c@posting.google.com... > (mapcar 'quote '("1" "2" "3"...

Re: Mandis Quotes (aka retiring """ and ''')
Russell Nelson wrote: > If you need to put a single quote in, then you put > an arbitrary string in-between the single quotes which does NOT > appear in the string. For example, "Bill's house" becomes > 'x'Bill's house'x'. So possible examples might be: 'xx'somebody's mother'xx' 'xy'somebody's father'xy' 'wink'somebody's uncle'wink' 'quote'somebody's body'quote' not terrible easy on the eyes, and why use the single quote at all? Why no= t use a similar pattern li...

Re: Mandis Quotes (aka retiring """ and ''') #2
Russell Nelson notes: > = > Choose poor examples, and then criticize them as poor choices? > = true enough, but the suggested scheme introduces another variable into the = language syntax; I might always make good choices <wink> on what delimiter = I choose, but I might also end up working on code written by someone else w= ho makes less good choices. Or vice versa. = > Exactly. It really would be better to have one(1) string literal > which can quote anything without reverting to backslashing. Why one? > Simpler parsing, simpler learning of the language, fewe...

JAXM returning '&lt;' and '&gt;' rather than "<" and ">"
Hi guys I'm up against a very annoying problem. I'm tryint to use JAXM to call a simple PHP nuSoap web service. I am using SOAPMessage/SOAPPart/SOAPEnvelope etc, however when i receive the message from the server i get: &lt;symbol&gt;great&lt;/symbol&gt; rather than: <symbol>great</symbol> Does anyone have any idea why its converting '<' to '&lt;'??? Any help would be most appreciated, i've been frustrated by this for hours! (Note the xml just dumps out "<symbol>great</symbol>" - it does not encode it ...

expect and tk, what is the name of expect's "send"
Hi. Under wish, I issue a package require Expect Who can tell me where the name of the expect "send" command, because the original's send command of Tk is still defined ? Thanks for help -- e-mail : Stephane.Mottelet@nospam.gnark.gnark <stephane.mottelet@nospam.gnark.gnark> wrote: > Under wish, I issue a > > package require Expect > > Who can tell me where the name of the expect "send" > command, because the original's send command of Tk > is still defined ? You are looking for "exp_send". All expect commands also have "exp_*" flavours (e.g. exp_spawn, exp_close), except commands that already begin with "exp". -- Glenn Jackman NCF Sysadmin glennj@ncf.ca stephane.mottelet@nospam.gnark.gnark wrote: >>You are looking for "exp_send". All expect commands also have "exp_*" >>flavours (e.g. exp_spawn, exp_close), except commands that already >>begin with "exp". One of these days someone should namespace 'em. close and continue already step on the core ones. Tcl Style Guide says libraries either script or complied shouldn't use the global namespace as it's reserved for the core (and top level user). -- David Gravereaux <davygrvy@pobox.com> $ make war make: *** No rule to make target `war'. Stop. Try `love' instead. Glenn Jackman wrote: ><stephane.mottelet@nospam.gnark.gnark> wrote: ...

"expected unqualified-id before 'using'"
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message: expected unqualified-id before "using" expected `,' or `;' before "using" which doesn't make any sense to me - a preprocessor directive isn't ended by a semicolon, and I must've used this little chunk of code hundreds of times. This happened after I chopped up an unwieldy large class into a couple of smaller classes, and this code ran just fine before I made the changes. The REALLY weird thing is that if I comment ou...

Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"'
Okay.I'm following the documentation that came with the PostgreSQL source code (located in /usr/doc/postgresql-7.3.4-2/html/arrays.hmtl in my cygwin root). I created have a table with a varchar array in it, kind of like the following: CREATE TABLE tbl_db_usuario_detalles (NOMBRE varchar(50), COD_USE varchar(6)[]); I've added a single record that has two values. It is imported from a tab-separated text file that has one line, like the following: Username {xxxxxx,yyyyyy} The import seems to work fine (if I put quotes around the string values in the array it fails). ...

"cannot convert parameter from 'short **' to 'void **'"
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'" Thanks, Igor On 2005-11-22, Igor Okulist <igor@remove_this_okulist.com> wrote: > int func(void**); > > { > short* p = NULL; > func(&p); //<<< here > } > > Could somebody remind me why is this not allowed ? error > message: "cannot convert parameter from 'short **' to 'void > **'" ...

env -i x=9 bash -c 'x=4;bash -c "echo x: /\$x/"' # then try w/o 'x=9'
Bug or feature? Pls explain: /tmp $ env -i bash -c 'x=4;bash -c "echo x: /\$x/"' x: // /tmp $ env -i x=9 bash -c 'x=4;bash -c "echo x: /\$x/"' x: /4/ --snip ~ $ uname -r; echo $BASH_VERSION 2.6.27.41-170.2.117.fc10.i686 3.2.39(1)-release -- thx On 2010-05-15, Name withheld by request <anonb6e9@nyx3.nyx.net> wrote: > Bug or feature? Pls explain: > > /tmp $ env -i bash -c 'x=4;bash -c "echo x: /\$x/"' > x: // > /tmp $ env -i x=9 bash -c 'x=4;bash -c "echo x: /\...

Re: Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"'
Okay...I answered my own question. I didn't understand from the directions that I had to compile and install the dll in contrib/array and run the array_iterator.sql. It works like a charm now. Mike -----Original Message----- From: Mike Leahy [mailto:mgleahy@fes.uwaterloo.ca] Sent: October 10, 2003 3:41 PM To: 'pgsql-general@postgresql.org' Subject: Unable to identify an operator '*=' for types 'character varying[]' and '"unknown"' Okay.I'm following the documentation that came with the PostgreSQL source code (located in /u...

Why doesn't Python's "robotparser" like Wikipedia's "robots.txt" file?
For some reason, Python's parser for "robots.txt" files doesn't like Wikipedia's "robots.txt" file: >>> import robotparser >>> url = 'http://wikipedia.org/robots.txt' >>> chk = robotparser.RobotFileParser() >>> chk.set_url(url) >>> chk.read() >>> testurl = 'http://wikipedia.org' >>> chk.can_fetch('Mozilla', testurl) False >>> The Wikipedia robots.txt file passes robots.txt validation, and it doesn't disallow unknown browsers. But the Python pars...

"Method 'Controls' of ojbect 'CommandBarPopup' failed" ?
I get this error every so often. Some bogus error number (such as -2147467259), too. Google searches imply that it can be caused by manually adding/deleting menu items on the fly, but it happens to me when a modal form is active and a timer function fires. Some of the code it runs (not sure what exactly) breaks it. Part of the menus are then hosed (i.e., you click and it doesn't "drop down", even if there are items in there). The only "solution" I've found is to resort to a backup and re-code everything since that point. Can anyone help me find a better soluti...

mini-tutorial needed: 'target=""' attribute for 'A'
What I knew, from back in the days of tab-less browsers: an anchor "tag" of form <A href="WhatHaveYou" target="_blank"> used to open a fresh browser window to display whatever the URI "WhatHaveYou" had on offer. In these days of tabbed browsers, though, there must be two attribute value candidates, one for spawning a new *window*, one for opening a new *tab*, and I'll be sempiternally grateful to whoever teaches me what they are. Cheers, and TIA, -- tlvp -- Avant de repondre, jeter la poubelle, SVP. In article <1gvfvb0tom0wx....

There's "Unix", and then there's "UNIX(r)"
From TOW[1]: The Open Group, an industry standards consortium, now owns the UNIX trademark and allows its use for certified operating systems compliant with its standard, the Single UNIX Specification. Other operating systems that emulate Unix to some extent may be called Unix-like, although the Open Group disapproves of this term.[4] The term Unix is also often used informally to denote any operating system that closely resembles the trademarked system. The most common version of Unix (bearing certification) is Apple's OS X, while Linux is the most popular non-certified workalike. So, to summarize: "Unix" is a class of operating systems that is "UNIX-like", which includes Linux. "UNIX(r)" is a trademark of the Open group, who -- somewhat snootily -- have an issue with the term "UNIX-like". (They can take a flying fsck.) "Cult of Unix" spells "Unix" as "Unix", because otherwise, what would it have to do with Linux? This PSA brought to you by the letter "U" and the number "2". -v Unix minions, unite! On 2/9/14, 1:15 PM, in article ld8nlg$bu7$1@dont-email.me, "vallor" <vallor@cultnix.org> wrote: > From TOW[1]: > > The Open Group, an industry standards consortium, now owns the UNIX > trademark and allows its use for certified operating systems > compliant with its standard, the Single UN...

Matlab7 'bug' when using "subplot" + "imagesc"?
Hi, Does anybody know if Matlab7 has a 'bug' when using "subplot" + "imagesc"? I use to work with Matlab6.5 and using "subplot" + "imagesc" together in the same Figure worked absolutely fine: ======================================= a) all subplots where of the same size, b) the distances between them was the appropiate, c) and the size of the colorbar was perfect and the same for all subplots. ======================================= However I am now using Matlab7 and to my surprise using "subplot" + "imagesc" together ...

v = json.loads("{'test':'test'}")
raise ValueError(errmsg("Expecting property name", s, end)) http://docs.python.org/library/json.html What am I doing wrong ? gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wrong ? You need proper quotation marks: >>> s = json.dumps({'test':'test'}) >>> s '{"test": "test"}' >>> json.loads(s) {u'test': u'test'} The JSON format is described here: http://www.json.org/ Peter On Jan 26, 5:12=A0am, gert <gert.cuyk...@gmail.com> wrote: > raise ValueError(errmsg("Expecting property name", s, end))http://docs.py= thon.org/library/json.html > What am I doing wrong ? You use wrong quotes, it should be wrapped by double quotes not single quotes. Read http://json.org/: "A string is a collection of zero or more Unicode characters, wrapped in double quotes, ..." >>> v =3D json.loads('{"test":"test"}') >>> v {u'test': u'test'} Please include all relevant information in the *body* of your message, not just in the subject. It's a pain having to piece a question back together between the subject. On Sun, 2009-01-25 at 13:12 -0800, gert wrote: > raise ValueError(errmsg("Expecting property name", s, end)) > http://docs.python.org/library/json.html > What am I doing wr...

'Parse error' problem in "isset" and "empty"
I've been having some problems with a parse error that I can't figure out (PHP 4.3.11 on Solaris9). Sample code: <?php // getting strange parse errors on this class A { var $value; function A() { $this->value = 1; } function getValue() { return $this->value; } } $a = new A(); if (!empty($a->getValue())) { echo "success"; } else { echo "failure"; } ?> The result of this is: Parse error: parse error, unexpected '(', expecting ')' in /foo/public_html/parse_errors.php on line 15 I also get the same effect with "iss...

"POSIX" quoting using $'string'
hello, world\n according to the zsh manual, http://zsh.sourceforge.net/Guide/zshguide05.html in section "5.1.3: POSIX quotes" quoting with $'string' is POSIX; it allows the usual backslash escapes known from C for \n etc in strings. Both bash and zsh implement this mechanism. I've been trying to find where POSIX specifies this by reading http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html but can't find it. Can someone point me to where this is specified? Regards, Jens -- Jens Schweikhardt http://www.schweikhardt.net/ SIGSIG -- signatu...