How to make send command of "expect" program to read from a file and use each line as argument.
I want to use a loop like structure in expect program which may look like below(NOTE:- while loop is imaginary.)
spawn /my/program
expect {
-re EBtxjjmEcQTxc0SLd4TdXxjUduxCOLZBwEme2Z.*password: {
while read_line in FILE;
do
send $read-line;
done
}
How to program the while-loop part equivalent using "expect"
Note in your question, you were missing a close brace, and you mis-typed your variable name ( read_line
and read-line
)
Expect is a Tcl extension, so you have all the Tcl commands at your disposal
spawn /my/program
expect {
-re EBtxjjmEcQTxc0SLd4TdXxjUduxCOLZBwEme2Z.*password: {
set fh [open FILE r]
while {[gets $fh read_line] != -1} {
send "$read_line\r"
}
close $fh
}
}
If you install tcllib , you can do
package require fileutil
spawn /my/program
expect {
-re EBtxjjmEcQTxc0SLd4TdXxjUduxCOLZBwEme2Z.*password: {
fileutil::foreachLine read_line FILE {
send "$read_line\r"
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.