develooper Front page | perl.beginners | Postings from February 2002

Re: TCl/Expect Question

Thread Previous
From:
William.Ampeh
Date:
February 7, 2002 09:16
Subject:
Re: TCl/Expect Question
Message ID:
OF17F369A1.F9F63387-ON85256B59.005E2FC1@frb.gov



This will do it:



#!/usr/local/bin/expect -f
#exp_internal 1                                   #<---------------  you
could uncomment this to turn debug mod on

set timeout 2
set prompt "(%|#|\\$) $"                ;# default prompt
log_user 1
catch {set prompt $env(EXPECT_PROMPT)}

eval spawn less foo.txt                     #<---------------- make sure
this points to your file

set my_i 0
set my_prompt "Press /, g, q, or t to proceed -> "

interact {
   "/" {send "/REPT\r"}
   "g" {send "g\r"; expect; send_user $my_prompt }
   "q" {send_user "\nDone\n\n"; exit}
   "t" {
      set my_i 0
      while 1 {
         if { $my_i < 3 } {
            incr my_i
            exp_send "f"
            send_user "panakj $my_i "          #<---------------- modify
this message
            sleep 2;
            expect               #<--------------- this was your problem.
Without some form of interaction, expect waits, in your case "panakj prints
3 times"
         } else {
            break                #after 3 attempts, exit the loop
         }
      }
      send_user $my_prompt                     #<------- just something fun
   }
   eof { send_user "End of the File!\n"; exit }
}

------------------------------------------------

I did not wast time on the second block, if you want me to, let me know.

__________________

William Ampeh (x3939)
Federal Reserve Board


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About