For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2007 > utter newbie expect question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author utter newbie expect question
Artis Gripemore

2007-05-29, 7:10 pm

Let me start by declaring that had I access to the Exploring book, I
would not be here posting this, I'd be figuring it out for myself and
leaving you to more interesting problems. Thanks for your patience
and any help you can offer.

My problem is that the application I want to control could generate,
at one point in its execution, any number (from 0 to 1000) "Press
<Space> to Continue" prompts, and I cannot for the life of me figure
out how to write an expect script that will deal with this. I need it
to send " " when this prompt appears, then check to see if it gets
that prompt again before it moves on, until it no longer gets that
prompt.

So it looks like this:

expect "(A, B, C"
send -- "c"
# at this point, we can get any number of "Press <Space>" prompts, to
which we need to send " " after capturing the response each time.
expect "(X, Y, Z"
send -- "y"
etc.

Thanks!

Mark Janssen

2007-05-29, 7:10 pm

On May 29, 5:43 pm, Artis Gripemore <wealthe...@yahoo.com> wrote:
> Let me start by declaring that had I access to the Exploring book, I
> would not be here posting this, I'd be figuring it out for myself and
> leaving you to more interesting problems. Thanks for your patience
> and any help you can offer.
>
> My problem is that the application I want to control could generate,
> at one point in its execution, any number (from 0 to 1000) "Press
> <Space> to Continue" prompts, and I cannot for the life of me figure
> out how to write an expect script that will deal with this. I need it
> to send " " when this prompt appears, then check to see if it gets
> that prompt again before it moves on, until it no longer gets that
> prompt.
>
> So it looks like this:
>
> expect "(A, B, C"
> send -- "c"
> # at this point, we can get any number of "Press <Space>" prompts, to
> which we need to send " " after capturing the response each time.
> expect "(X, Y, Z"
> send -- "y"
> etc.
>
> Thanks!


Something like:

expect {
"<Space> to Continue" {send " " ; exp_continue}
"(X, Y, Z" {send -- "y"}
}

Should do the trick. This will wait for either "(X, Y, Z" and send yes
or wait for the <Space> line and send a space in response and then
wait for either a <Space> line or a X, Y, Z line again.


Mark

Artis Gripemore

2007-05-30, 8:07 am

On May 29, 5:30 pm, Mark Janssen <mpc.jans...@gmail.com> wrote:
> On May 29, 11:03 pm, Artis Gripemore <wealthe...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Are you using autoexpect by any chance? In that case conservative mode
> makes sense.
>
> Mark- Hide quoted text -
>
> - Show quoted text -



Yes, I did use autoexpect -p to build the original script. Lots of
editing. Next time, by hand.

The script outruns the application at one point, so I have simulated
the delay by inserting sleeps.
I know that there is some kind of "human typing" option, but I haven't
looked into it yet. I'm just happy that the major stumbling blocks
are overcome.

One thing that looks interesting to try next -- have the script read
the menu it has accessed, to ensure the correctness of the next
exp_send. If the correct choice off a given menu, say foo, is 16 most
of the time, but can be 17 some of the time, it would be to read
in from the buffer and then use the number associated with foo in the
corresponding exp_send.

I gotta get that book.

Artis Gripemore

2007-05-30, 7:10 pm

On May 29, 6:23 pm, cla...@lairds.us (Cameron Laird) wrote:
> In article <1180472623.821578.15...@u30g2000hsc.googlegroups.com>,
> Artis Gripemore <wealthe...@yahoo.com> wrote:>It would appear to be working now. I did change all the sends to
>
>
> .
> .
> .
> The sleeps are generally a symptom that there's a better coding
> available. It's unlikely they're helping in other than a super-
> ficial way.


I'm sure that you are right about that. The app does fail at one
point with the script going full out, but I doubt that the delays are
needed everywhere I put them.

Thanks!

Cameron Laird

2007-05-30, 7:10 pm

In article <1180533175.419845.307710@g4g2000hsf.googlegroups.com>,
Artis Gripemore <wealtheow1@yahoo.com> wrote:
>On May 29, 6:23 pm, cla...@lairds.us (Cameron Laird) wrote:
>working now. I did change all the sends to
>
>I'm sure that you are right about that. The app does fail at one
>point with the script going full out, but I doubt that the delays are
>needed everywhere I put them.
>
>Thanks!
>


Are you using

sleep ...

in place of a sufficiently specific

expect ...

? I urge you to reconsider the latter.
Artis Gripemore

2007-05-30, 7:10 pm

On May 30, 10:37 am, cla...@lairds.us (Cameron Laird) wrote:
> In article <1180533175.419845.307...@g4g2000hsf.googlegroups.com>,
> Artis Gripemore <wealthe...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
>
> Are you using
>
> sleep ...
>
> in place of a sufficiently specific
>
> expect ...
>
> ? I urge you to reconsider the latter.- Hide quoted text -
>
> - Show quoted text -


I will do so. I never stop trying to make these things better.

Thanks again.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com