1

Environment

Linux version 2.6
Screen version 4.03.01

I am running an application inside of a screen session. The program prints to STDOUT and reads from STDIN.

What I would like to do:

First, have STDOUT of the screen tee'd to a file. For some reason, piping to tee only writes the first few lines, then stops. This maybe because the shell script I am executing runs other applications/shell scripts... Is there a way to connect to the STDOUT of the screen session?

Second, I would like to create a file, like a fifo maybe?, that I can write data do and have it send that data to the STDIN of the screen session.

I am open to other suggestions, such as not using screen at all and doing something with nohup and some fifo's

Basically, I want to background an application and have a file that I can tail for the output and another to redirect input to.

1 Answer 1

1

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.)

7
  • 1
    Read my post. ;)
    – Tim
    Commented May 21, 2017 at 1:36
  • @varlogtim Read my answer. I quoted the summary sentence from your post and did what the quote asked. If you want something else, please be clear and precise.
    – John1024
    Commented May 21, 2017 at 1:38
  • Read stdout and write to stdin of a screen session, preferably with fifo files.
    – Tim
    Commented May 21, 2017 at 1:39
  • For some reason, as stated, piping the program output only contains the first couple of lines then stops.
    – Tim
    Commented May 21, 2017 at 1:42
  • 1
    Does your application flush its output? Commented May 21, 2017 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .