I'm trying to figure out how to make a script that will be able to send commands to a screen that will execute within whatever the screen is doing. Is this possible, and if so, how is it done? I've already tried screen -X etc, and it is not executing the commands.
Asked
Active
Viewed 2.9k times
8
-
I don't think you can do this once the screen is already running. What do you suppose might happen if a program (other than the shell) is already running and accepting input? – Falcon Momot Jan 07 '14 at 13:12
1 Answers
6
Well it depends on the commands you need to execute:
If you need to execute commands in an existing screen session, you need to re-attach and execute the commands using this command line:
screen -r -S "<screenName>" "command/or/script/to/execute"
If want to execute the commands inside of a new screen session, you can use this:
screen -A -m -d -S "<screenName>" "command/or/script/to/execute"
You can read more about some common screen commands here: 10 Screen Command Examples to Manage Linux Terminals

Pysis
- 147
-
It sounds as though
screen -X
is what the questioner really wants, but for some reason it's not working for him. That is, he wants to run a command in an existing screen session without having to attach to it. – Andrew Schulman Jan 07 '14 at 07:06 -
Wouldn't putting the command in graves like that cause the local shell to interpret it in the calling shell and paste its output as arguments to screen? – Falcon Momot Jan 07 '14 at 13:11
-