What I'd like to do is send a single file "repeatedly" (like cat'ing it an infinite number of times) as input to another program. Is there a way on the command line/using bash?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
Appears it is possible through the use of
mkfifo
(this way allows for easy control, restartability, and large files)Then write to that fifo "looping" from one bash prompt, ex: create script named bash_write_eternal.sh:
run that in one terminal
(you could background it also if you want to reuse the same terminal)
then in another terminal, run your input program, like
or
your program will now receive an eternal input of that file looping over and over. You can even "pause" the receiving program by interrupting the terminal running the
bash_write_eternal.sh
script (its input will be suspended until you resume the fifo writing script).Another benefit is "resumable" between invocations, and also if your program happens to not know how to receive input from "stdin" it can receive it from a filename here.
A
while :
loop repeats forever:To use a helper function:
Process substitution provides a mechanism by which bash can generate a temporary, readable filename connected to an arbitrary chunk of bash code for you:
This will create a
/dev/fd/NN
-style name on operating systems that support it, or a named pipe otherwise.Yes.
The
yes
command, using the file's contents as it's argument: