Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect: sending multiple statements in one send command

Status
Not open for further replies.

nkhambal

Technical User
Sep 6, 2006
2
US
Hi,

I am trying to write a customized library for configuring routers. In my config proc I send a "List" of commands and "join" then with "\r". However, using send/expect in proc limits my ability to send one command at a time. I send a command and I check for prompt returned by router. What I want to do it send all the commands at once in a single send and then expect the prompt as against sending one command at a time. This is what I tried.

set cmd [join $cmd "\r"]
send -i $procid "$cmd\r"
expect -i $procid -re "$prompt#"
lappend buff $expect_out(buffer)

However, not all the commands get sent. Sending stops in the middle of the list and my program quits. I tried adding full_buffer in my expect statement (I don't know if thats the right use of it) and it did send all the commands, however, it halted after that and errored out saying it could not find the variable expect_out(buffer).

Any ideas how to achieve this?

Pls suggest.

Thanks,
 
okay,

Following worked for me.
Code:
 set lastcmd [lindex $cmd [expr [llength $cmd] - 1]]
    set cmd [join $cmd "\r"]
    send -i $procid "$cmd\r"   
    expect {
        -i $procid -re "$lastcmd" {
	    lappend buff $expect_out(buffer)
	}
	full_buffer {
	    puts "buffer full"
            lappend buff $expect_out(buffer)	    
	    exp_continue
	}
	timeout {
	    puts "timeout occured"
	    lappend buff $expect_out(buffer)
	    exp_continue
	}
    }
Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top