Currently I am using a script to spawn a daemon:
screen -r user -X stuff "spawn daemon"
screen -r user -X eval "stuff \015"
Is there an easier way to send the enter key ("\015"), or in fact a better way of doing this? (I have to use screen.)
I assume that because I'm not attaching the screen, I won't be able to get the outcome/output of the "spawn daemon" command. Is that correct?
Ctrl-A followed by the letter 'a' will send the Ctrl-A sequence to the shell. Save this answer.
Log files of current screen sessions can be started with the Ctrl+a H command, which will make a file called screenlog. X where X is the number of your screen session. A screenshot of what is currently in your screen window can be invoked with Ctrl+a h, creating a file called hardcopy.
Sending commands to screenscreen has the -X flag which allows you to send a (screen) command to a session. The -p 0 flag is for the window inside screen. If you have created multiple windows ( CTRL+A c ) you can specify the number. With CTRL+A [0-9] you can directly go to that window inside screen.
Also called the "Return key," it is the keyboard key that is pressed to signal the computer to input the line of data or the command that has just been typed.
I always do it like this:
screen -r user -X stuff "spawn daemon^M"
where I get the ^M by hitting ctrl-v, then Enter, on the command line. In bash and vim, ctrl-v can be used to escape characters like Enter that would otherwise have a special effect.
As for the second question, you can enable logging, and read from the log file.
This solution is working in my case:
screen -r user -X stuff "spawn daemon$(printf \\r)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With