Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2014-07-17T18:28:24Z by 83PT_Don_Ellis
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic Expect Script - For condition

‏2005-01-27T07:30:20Z |
I am working on an Expect script that is killing me. Everytime I try the For loop below, it fails. To my eye, my For loop is identical to all examples I've seen. I've even removed all the internal commands of the loop. The For loop still fails. I've even passed in a sample For loop from another user (presumably theirs worked) and it failed. Please help! Below is the script and the error.

for {set i 0} {$i<5} {incr i 1}
{
send -- "$command"
send -- "\r"
set timeout 1800
expect
{
"Unrecognized" {set i 5 continue}
"Invalid" {set i 5}
"Missing" {set i 5}
"busy" {puts "System busy, will retry." sleep 30 continue }
"later" {puts "System busy, will retry." sleep 30 continue }
"progress" {puts "System busy, will retry." sleep 30 continue }
timeout {set i 5}
"$cmd_result" {set i 5 continue}

}
}
Here is the error I get :
wrong # args: should be "for start test next command"
while compiling
"for {set i 0} {$i<5} {incr i 1}"
(file "/export/home/ss7admin/stp_scripts//exp//run_eagle_seculog_condition_results.exp" line 88)
0
Updated on 2005-01-28T06:40:41Z at 2005-01-28T06:40:41Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Expect Script - For condition

    ‏2005-01-28T06:40:41Z  in response to SystemAdmin
    Several people from another forum helped me out with this. I wanted to post the answer here so anyone else with the same problem will get an answer.

    Here it is ::
    > for {set i 0} {$i<5} {incr i 1}
    > {
    > wrong # args: should be "for start test next command"

    Indeed you are missing "command" argument -- the loop body.

    You should have typed:

    for {set i 0} {$i<5} {incr i 1} {

    The brace on the next line is not part of the same command.
    If you really want that look, then you must end the line with a
    backslash

    for {set i 0} {$i<5} {incr i 1} \
    {

    I really hate this style, particularly because it requires the
    backslash to be the last character -- trailing spaces will break
    it.

    • 83PT_Don_Ellis
      83PT_Don_Ellis
      1 Post
      ACCEPTED ANSWER

      Re: Expect Script - For condition

      ‏2014-07-17T18:28:24Z  in response to SystemAdmin

      [Apology: This is my first day "working" with TCL]

      Question: isn't it also required that the open brace for the expect statement be on the same line, or is this an inconsistency in TCL?

      In another example (Brian Smith's ... Blog : When to use Expect scripting and when to avoid it), he shows all open braces on the same line with the command.