Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easier way to send ENTER key in GNU Screen?

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?

like image 320
Dijkstra Avatar asked Jan 18 '11 16:01

Dijkstra


People also ask

How do you send Ctrl a screen?

Ctrl-A followed by the letter 'a' will send the Ctrl-A sequence to the shell. Save this answer.

What is the command used for simple use of GNU screen?

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.

How do you send a command to a screen session?

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.

What is Enter key in Unix?

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.


3 Answers

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.

like image 158
traversable Avatar answered Sep 22 '22 05:09

traversable


As for the second question, you can enable logging, and read from the log file.

like image 45
maxelost Avatar answered Sep 20 '22 05:09

maxelost


This solution is working in my case:

screen -r user -X stuff "spawn daemon$(printf \\r)"
like image 33
pablorsk Avatar answered Sep 22 '22 05:09

pablorsk