I have a Python executable, written and compiled by somebody else, that I simply need to run once halfway down my own bash script. The program uses a text-based UI, therefore waits for input before proceeding, but the key operations it performs when starting are required in my bash script. A messy (and strange) procedure I know, but unfortunately I haven't got any other options.
I've gotten around forcefully closing the program with a kill signal, but the program's TUI insists on outputting to wherever it's run. I've tried redirecting both stdout and stderr to /dev/null and running the program in the background by suffixing an ampersand, but simply can't get it to play ball. I believe the cause is the program spawns other processes, and the output redirection of the parent process doesn't affect them. Is there any trick I can utilise to redirect all output from child processes too?
The program may be writing to the tty instead of stdout. You may be able to use the
unbuffer
script that comes withexpect
or some other technique usingexpect
or something similar.Here's a demonstration. Create this script and call it "writetty". Then do
chmod u+x writetty
:Now try it out:
You could use
expect
to respond to the program's request for input instead of killing it.