Basically, I want to background an application and have a file that I can tail for the output and another to redirect input to.
If that is the case, then (1) we need to background application
and send its output to file file
:
application >file &
And, (2) we need to tail application's output to command another
:
tail -f | another
Example
Let's create a sample application
and another
:
$ application() { while sleep 1; do date; done; } $ another() { grep 2017; }
Now, let's start application
in the background:
$ application >file & [1] 5989
And, let's run another
in the foreground:
$ tail -f file | another Sat May 20 18:32:05 PDT 2017 Sat May 20 18:32:06 PDT 2017 Sat May 20 18:32:07 PDT 2017 Sat May 20 18:32:08 PDT 2017 Sat May 20 18:32:09 PDT 2017 Sat May 20 18:32:10 PDT 2017 [...clip...]
Inside a screen session using a FIFO
First, start a screen session. Then run:
$ mkfifo fifo $ application >fifo & [1] 8129 $ cat fifo | another Sat May 20 18:50:39 PDT 2017 Sat May 20 18:50:40 PDT 2017 Sat May 20 18:50:41 PDT 2017 Sat May 20 18:50:42 PDT 2017 Sat May 20 18:50:43 PDT 2017 Sat May 20 18:50:44 PDT 2017 Sat May 20 18:50:45 PDT 2017 Sat May 20 18:50:46 PDT 2017 [...snip...]
(I used cat fifo | another
for its parallism to the first tail -f
version. cat
is unnecessary here. We could have used another <fifo
.)