Expect - Expecting while interacting
expect
Solution
You can use the `expect_background` command. From the man page:
takes the same arguments as expect, however it returns immediately. Patterns are tested whenever new input arrives.
You can modify your initial script like this:
#!/usr/bin/expect
proc yay {} {
send_user "Yay\n"
}
trap { # trap sigwinch and pass it to the child we spawned
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
spawn bash
expect_background {
fuzz yay
}
interact -re "HOT" {
yay
}
Problem
I want to "listen" for a string outputted by the shell, while being in "interact" mode. Or i want to emulate interact mode somehow, that still allows me to listen for a specific string from the shell. It seems `interact` only listens to the users input (the keys I press) and not what is returned by the shell. How would I go about having Expect executing something everytime it sees a specific string, but otherwise let me use the shell interactively an unhindered?. Example: ``` proc yay {} { send_user "Yay\n" } trap { # trap sigwinch and pass it to the child we spawned set rows [stty rows] set cols [stty columns] stty rows $rows columns $cols < $spawn_out(slave,name) } WINCH spawn bash interact { interact -re "HOT" { yay } expect { fuzz yay } } ``` If i run this and type "HOT" it responds with "Yay". As expected, it read my keys. But if i type ``` echo fuzz ``` The "expect" clause doesnt get triggered. Also "echo HOT" wont trigger anything either. So is this possible or am I missing somthing. Perhaps I'd need to emulate `interact` in some kind of "expect, continue"-loop. Its just important that everything works normally in the shell.. Suggestions anyone?