Seems like expect's interact does not work when I redirect stdin to an expect script. (See examples below.)
Is this a bug? Expected behavior?
How do I make expect pass its stdin onto a spawned program when it is redirected (from a file or a pipe)?
$ expect -c 'spawn sleep 3' -c interact
==> sleeps for 3 seconds (good!)
$ expect -c 'spawn sleep 3' -c interact < /dev/null
==> exits immediately (not what I'd like to happen)
$ expect -c 'spawn sleep 3' -c interact < /dev/zero
==> prints a bunch of \0s then exits after 6 seconds (strange)
$ tail -f myemptyfile | expect -c 'spawn sleep 3' -c interact
==> sleeps indefinitely, or so it seems (it shouldn't)
I am running expect 5.42.1 on Linux. Thanks!
If you need to have expect pass stdin onto a spawned process then deal with the pass stdin as if it were arguments passed to expect using the variable $argv
There might be a better way. What is the goal behind having expect pass stdin onto a spawned process?
Say I have a program processNames that accepts user input, computes something, prints something, then accepts more user input, etc. processNames is quirky (e.g. requires stdin/stdout to be a terminal) and I can't change it.
I would like to (a) wrap processNames in an expect script (e.g. as a workaround for the terminal requirement) and (b) be able to invoke that expect script just like I'd invoke processNames itself, i.e., either interactively or with stdin/stdout redirect.
How would I write such a script?
There is another issue with redirects. Say we have this test.exp:
spawn sleep 3
If I run it as 'expect test.exp' I get the "done" message as expected.
If I say
expect test.exp < /dev/null # or some file
I get this:
spawn sleep 3
send: spawn id exp0 not open
(file "test.exp" line 3)
This looks like a bug? Any workarounds?