Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can we clear buffer value for expect_out in expect scripting

2,245 views
Skip to first unread message

bhargava tadi

unread,
Aug 23, 2012, 8:09:17 AM8/23/12
to
Hi All,

i was wrinting expect script for automate application program on OS. So for this i am using expect_out(0,string) funtion twice in the program and i am comparing inputs of same pattern twice. But the problem is that i need to clear the buffer once i capture the output for the first time, i was stucked at that instance, please let me know how to clear the buffer

I am giving my sudo code here,

expect {
-re "(0x\[0-9a-f\]+)" {
set killid $expect_out(0,string) -- here i get output as "0xb4046a"
}
}
expect $prompt
switch -regexp $killid {
(0x*[a-f])?$ {
send "kill $id\r"
}
default {send_user "There is no process to kill the installed application\r"}
}

....
... After getting that process id i am using expect_out in my source code ...

send "install test /home/usr/test1\r"
expect $prompt
send "create test\r" -- for ex: output of this is "0xd004df"
expect {
-re "(0x\[0-9a-f\]+)" {
set pid $expect_out(1,string)
}
expect $prompt
send "start $pid\r"


when i am comparing for second pattern matching, the first pattern was already stored in buffer and for second it was not storing in the buffer. whenever i am starting start $pid means i getting the value of "0xb4046a", so my application is unable to install.

i got to know the problem where was occured and by referring man pages we can clear the buffer by passing argument as "*" and ".*" to expect_out. But unable to implement that one. can any bodyhelp for my problem. Thanks in advance

Uwe Klein

unread,
Aug 23, 2012, 9:07:39 AM8/23/12
to
add timeout and eof cases to your expect invocations to decrease opaqueness, please,

i.e.
expect \
-re $patt.. {
set myvar $expect_out(...
} eof {
puts stderr EOF!
} timeout {
puts stderr TIMEOUT!
}

same with expecting the prompt.

THen look into your prompt.
Most apps produce prompts with trailing whitepspace.

Not expecting that whitespace leads to strange
seemingly timing dependent errors

uwe
0 new messages