GNU Screen – Sending Input to a Screen Session from Outside

gnu-screen

My scenario is this:

I have a screen session running in a remote location. Inside this screen is a consoled-based program. When run without screen, this program starts in the terminal and accepts commands on its standard input.

What I want is a way to remotely send a command to screen so that this command is received by the console program. Maybe like this:

My PC -> SSH Send Msg Auto -> Screen Session -> Program (Run command received)

So from a remote PC I can send via SSH commands to the screen which sends them to the program. The program accepts them and executes them.

Best Answer

If I understand correctly, you want to send input to a program running inside a screen session. You can do this with screen's stuff command. Use screen's -X option to execute a command in a screen session without attaching to it.

screen -S sessionname -p windowname -X stuff 'command1
command2
'

If you want to see the program's output, see the hardcopy, log and logfile commands.

Related Question