I am running an expect
script that will generate some dynamic input coming from stdin
.
Is there a way/pattern that addresses the concept of reading from the stdin and storing (?) somewhere the relevant input to be processed/parsed in a latter step?
example :
./myexpectscript.sh arg1 arg2 ..
Running command with id 9494
Running command with id 9494
Running command with id 9494
Running command with id 9494
Command execution finished
I actually want to store the above id, 9494
.
The script actually runs an api call to a remote server and has a duration of several seconds (for what that matters).
edit : the following snippet does not seem to resolve the issue:
expect -re Running command with id [0-9]+
set output \$expect_out(1,string)
as it gives me an error:
invalid command name "0-9"
while executing
"0-9"
invoked from within
"expect -re Running command with id [0-9]+"
(file "./myexpectscript.sh" line 17)
have also tried it with quotes, ie
expect -re "Running command with id [0-9]+"
Use {...}
to define your regex, use \\d
for decimal number, and capture the string with (...)
.
Set a variable with the captured string with $expect_out
.
expect -re {Running command with id (\d+)} {
set cmd_id $expect_out(1,string)
}
puts $cmd_id
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.