Currently, I am using a software script that requires continuous input through the terminal. The script evaluates files continuously by receiving path input and evaluating the file in the path.
The goal: Is it possible to run a script requiring input through passing input from another terminal or script.
The evaluation software loads a lot of data before being ready for processing, that is why I would prefer to keep the software running and simply pass input from time to time. Instead of starting up the software and load all data required (which takes time).
I can mention that I have tried tty to find:
$ /dev/pts/19
then through other terminal run: $ <command> <myinput> > /dev/pts/19
where command is replaced with 'echo / print'
However, it just prints in the other terminal, it does not act as input to the software.
Create a named pipe:
mkfifo pipe
Make sure it won't close (see this answer):
exec 3<>pipe
Feed your script from the pipe:
<pipe your_script.sh
# or if you want to see incoming data
<pipe tee >(your_script.sh)
Then from another terminal use echo
, printf
or whatever:
echo "/some/path/or/another/input" > pipe
or
cat large_input.txt > pipe
or
script_that_generates_input.sh > pipe
But beware of race condition! Don't feed the pipe from two or more sources at the same time; always wait for the current feeding command to exit before you run the next. Note if one source passes a lot of data, it may be held midway, until the receiving side processes the data. Put mbuffer
(with arguments that fit your usage case) before your_script.sh
to create a buffer that can store more incoming data before any feeding command is put on hold.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments