I've been searching to find a way to send a command to a detached screen session. So far, so good. This is what I've come up with:
$ screen -S test -p 0 -X stuff 'command\n'
This command works as it should. But, I would like the output from it too, echoed straight in front of my eyes (no need for a .log
file or something, I just want the output).
Using the screen -L
command, is not an option.
Best Answer
Use a first in first out pipe:
Use a redirect operator. Redirect command's output to /tmp/test for example like this:
Then in another shell
Note you may also want to redirect error messages using the 2>&1 operator.
Example
As requested in the comments, let's assume we have a php script accepting user input and printing the server load on the input of "status":
You create two fifos:
You call a screen:
In another console, let's call it console 2 you find out the name of your screen:
In console 2 you send the command to the screen:
you see the command appearing in the screen. Now in console 2 you can send commands to your php process:
and read from it: