For Programmers: Free Programming Magazines  


Home > Archive > Tcl > June 2007 > Expecting multiple pattern









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 Expecting multiple pattern
rick

2007-06-23, 4:18 am

I am expecting multiple reponse to a command, and then action
corresponding to some of the pattern is same, i want to combine such
patterns (variables) , so that i dont need to type in the same piece
of code again.

expect {

"qqq" { ............... }
"rrrr" { ..................}
"zzz" or "yyy" {..........}
}

My action corresponding to zzz and yyy is common ( zzz and yyy are in
actual complex pattern in my scripts, this is just an example), so how
can i group them as a single case

Uwe Klein

2007-06-23, 4:18 am

rick wrote:
> I am expecting multiple reponse to a command, and then action
> corresponding to some of the pattern is same, i want to combine such
> patterns (variables) , so that i dont need to type in the same piece
> of code again.
>
> expect {
>
> "qqq" { ............... }
> "rrrr" { ..................}
> "zzz" or "yyy" {..........}
> }
>
> My action corresponding to zzz and yyy is common ( zzz and yyy are in
> actual complex pattern in my scripts, this is just an example), so how
> can i group them as a single case
>


from the expect manpage ( see the failed / invalid password case):
expect {
busy {puts busy\n ; exp_continue}
-re "failed|invalid password" abort
timeout abort
connected
}

The construct that is used in switch like

switch $value -- $pata - $patb $actionscript

does not work.

uwe

rick

2007-06-23, 4:18 am

On Jun 22, 6:43 pm, Uwe Klein <uwe_klein_habertw...@t-online.de>
wrote:
> rick wrote:
>
>
>
>
> from the expect manpage ( see the failed / invalid password case):
> expect {
> busy {puts busy\n ; exp_continue}
> -re "failed|invalid password" abort
> timeout abort
> connected
> }
>
> The construct that is used in switch like
>
> switch $value -- $pata - $patb $actionscript
>
> does not work.
>
> uwe



Hi Uwe,

expect {
-re "$a | $b" {....}
timeout {...}
}

It is not working for me and taking me to the timeout case.
Also exp_internal is also not showing anything...

I earlier trying using the "switch" kinda approach (-), it cannt find
-, but through exp_internal I found that it matched one of the two
patterns.


rick

2007-06-23, 4:18 am


exp_internal shows that , it is taking "$a | $b" as a single pattern
and hence is not able to match.

Uwe Klein

2007-06-23, 4:18 am

rick wrote:
> On Jun 22, 6:43 pm, Uwe Klein <uwe_klein_habertw...@t-online.de>
> wrote:
>
>
>
>
> Hi Uwe,
>
> expect {
> -re "$a | $b" {....}
> timeout {...}
> }
>
> It is not working for me and taking me to the timeout case.
> Also exp_internal is also not showing anything...
>
> I earlier trying using the "switch" kinda approach (-), it cannt find
> -, but through exp_internal I found that it matched one of the two
> patterns.
>

If you use the single argument style for expect you do not get
variable substitution in the patterns ( and you added spaces in the RE
aswell.
Try:
set pata ABCDEF
set patb VWXYZ
expect \
-re "$pata|$patb" {
puts stderr MATCHED:a|b
} timeout {
puts stderr TIMEOUT
}



G!
uwe
Glenn Jackman

2007-06-23, 4:18 am

At 2007-06-22 09:24AM, "rick" wrote:
> I am expecting multiple reponse to a command, and then action
> corresponding to some of the pattern is same, i want to combine such
> patterns (variables) , so that i dont need to type in the same piece
> of code again.
>
> expect {
>
> "qqq" { ............... }
> "rrrr" { ..................}
> "zzz" or "yyy" {..........}
> }
>
> My action corresponding to zzz and yyy is common ( zzz and yyy are in
> actual complex pattern in my scripts, this is just an example), so how
> can i group them as a single case


Another approach is to write that common code as a proc, so:

proc ZorY {} {
blah
}
expect {
qqq {do qqq stuff}
zzz {ZorY}
yyy {ZorY}
}


--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
rick

2007-06-23, 4:18 am


Uwe,

I tried using your approach , but still no success.
Actually, substitution is occuring ; but after substituting $pata,
$patb it is taking "ABCDEF|VWXYZ" as single pattern, and hence not
able to match.

Glenn,

Yes, a proc can be written, but I was looking something like the way
Uwe suggested, which is somehow not working for me

Addick44

2007-06-23, 5:05 am

Alyssa Milano In Black Licking Snatch In Public!

http://www.WatchingTheTube.com/c?q=1673286

porn movie clip madonna pussy anal movies credit epic movie watch tarot gratis
free porn movie movie listing charlotte nc 2007 cruise joyner tom larry movie sexe britney pussy show spear
google video clip clip kardashian kim sex chat de gratis wecam free porn sex underwater video madonna sex free video
paris hilton xxx movie movie film matura wholesale adult video free naked cartoon video adult site upload video

adult xxx movie
clip funny sex video
adult pay per view movie
michael jackson photo
wild girl free video
free mature adult video
adult movie on demand
porn cartoon disney video
buy dvd movie shop
best girl lesbian video
Bezoar

2007-06-25, 4:23 am

On Jun 22, 11:08 am, rick <vagabond_maver...@yahoo.com> wrote:
> Uwe,
>
> I tried using your approach , but still no success.
> Actually, substitution is occuring ; but after substituting $pata,
> $patb it is taking "ABCDEF|VWXYZ" as single pattern, and hence not
> able to match.
>
> Glenn,
>
> Yes, a proc can be written, but I was looking something like the way
> Uwe suggested, which is somehow not working for me



Remember that when you are evaluating a regexp ( ie enclosing in "" )
that you must escape all special characters
as many times as necessary.

For instance, if you expect a string like this from your application:

the [man] was in "trouble".

The output will match regexp ( note) the braces:
{the \[man\] was in \"trouble\"\.}
but not
"the \[man\] was in \"trouble\"\.".

So if you surround your regexp with quotes you must excape twice or
ensure that you use braces
to prevent evaluation. See the following interaction .

% set buffer "the \[man\] was in \"trouble\"."
the [man] was in "trouble".
% regexp {the \[man\] was in \"trouble\"\.} $buffer
1
% set reg {the \[man\] was in \"trouble\"\.}
the \[man\] was in \"trouble\"\.
% regexp "$reg" $buffer
1
% set reg "the \[man\] was in \"trouble\"\."
the [man] was in "trouble".
% regexp "$reg" $buffer
0
% set reg "the \\\[man\\\] was in \\\"trouble\\\"\\."
the \[man\] was in \"trouble\"\.
% regexp "$reg" $buffer
1
%

Carl

Sponsored Links







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

Copyright 2008 codecomments.com