1

I'm attempting to create a detached screen and then send it a command, but this doesn't seem to be working.

If I enter the following commands:

$ screen -ls
No Sockets found in /var/run/screen/S-ec2-user.

$ screen -dmS myscreen
$ screen -ls
There is a screen on:
    9175.myscreen   (Detached)
1 Socket in /var/run/screen/S-ec2-user.

$ screen -S myscreen -X ls

Then I attached to the screen to see if the command executed:

$ screen -r myscreen

All I get is a blank command-line, as if nothing happened.

Does anyone know why this is failing, and what commands I can use to actually get the command to run inside the screen?

Note: I want to stay detached from the screen if possible, and just send commands into the screen from outside. This is because my plan is to run multiple screens, using an automated means (e.g. bash script).

1

Finally got this to work.

Looking at some code samples of screen usage, it seems that the -X parameter expects the word: stuff before the actual command, and also the command has to be wrapped in double quotes ("xyz").

Also to make the command run, the Enter keystroke has to be sent along with it. Going off this article on inserting special characters, I managed to input the keystroke by pressing Ctrl+V, Enter.

Command line looked like this:

$ screen -S myscreen -X stuff 'ls^M'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.