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
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.