I need to start a process, lets say foo
. I would like to see the stdout/stderr as normal, but grep
the stderr for string bar
. Once bar
is found in the
stderr foo
should be killed.
Is this possible?
Expect is designed for taking actions based on output from a process. The simplest solution is to simply let Expect start the process, then exit when it sees the expected output. For example:
expect -c 'set msg {Saw "foo" on stderr. Exiting process.}
spawn /bin/bash -c "echo foo >&2; sleep 10"
expect "foo" { puts $msg; exit }'
If the spawned process ends normally (e.g. before "foo" is seen), then the Expect script will exit, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With