Expect Script using the split command?

Hello All,

I have an Expect Script that ssh'es to a server and does some stuff.
In Expect there is a built-in Array Variable called "expect_out(buffer)" which contains all the output from the previous send command up until the expected output.

I want to pass the array "expect_out(buffer)" to a Procedure/Function I have.
After I pass the array I have a loop that I use to loop through each element line by line.

I am able to successfully do this loop outside of the Procedure using that expect_out(buffer) array...
So how can I convert this code below, to use a new array variable argument in the procedure?

### This loop works outside of this procedure...
foreach line [split $expect_out(buffer) "\n"] {
          send_user "Line = $line\n"
}

So how can I basically do the same thing as above, but this time I have to change the split function to use this new Array Variable "outputArray" that had "expect_out(buffer)" passed into it?

proc save_outputBuffer { outputArray } {

    foreach line [ split *NEW ARRAY* "\n"] {
          send_user "LINE = $line\n"
    }

    return $outputArray

}

I've tried a couple of different ways to do the split command but nothing seems to work...

Any thoughts would be great!

Thanks in Advance,
Matt

Define proc like this:

proc save_outputBuffer { outputArray } {
    foreach line [ split $outputArray "\n" ] {
        send_user "LINE = $line\r\n"
    }
    return $outputArray
}

Call it like this:

set myArray [ save_outputBuffer $expect_out(buffer) ]
1 Like

Hey Chubler_XL, thanks for the reply!

I tried it like you have it inside the proc, but I definitely didn't call it like you had though.
I'll give that a try and post back....

Thanks Again,
Matt

---------- Post updated at 10:25 AM ---------- Previous update was at 09:31 AM ----------

Hey there again Chubler_XL...

I tried out your example and it works like a charm! :b:
Thanks again for your help!

Thanks Again,
Matt