Send command to an already running screen session

gnu-screenopensolarissession

I have been trying to send commands to a running gnu screen session (4.00.03) in opensolaris, but cannot get it to run any commands through any combination of screen -X

Ok, I start a screen session with screen -S test, and then tried to with screen -r -X "date"to just show me the date, when I would reconnect to it. But neither an error message nor output in the screen happened. I tried with so many combinations, that I can't even remember.

Any hints on how to accomplish it?

The reason why I am doing this is, because I have a program, which does not come as a daemon, and I wish to start it in a screen session, so I can later on see what is going on.

Best Answer

Actually it's quite simple. You can use the following:

screen -S sessionname -X stuff 'command'`echo -ne '\015'`

echo -ne '\015' emulates pressing the Enter key.

NOTE: that 'stuff' is a screen command. http://www.gnu.org/software/screen/manual/screen.html#Stuff

Related Question