Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Screen - create screen in background run command from shell or script

I am trying to create a screen session/window from the shell and launch a command in it. How would I do that?

like image 789
jahil Avatar asked Jul 15 '12 12:07

jahil


1 Answers

If you want to launch and connect to screen:

screen CMD

If you want to launch and not connect to screen:

screen -dm CMD

Works with sessions too:

screen -Sdm NewDetachedSessionName CMD

You can send keypresses to CMD with stuff:

screen -S NewDetachedSessionName -X stuff "keypresses"

To send a new-line, include \n or ^M or $'\n' with the keypresses.

like image 186
Thor Avatar answered Oct 31 '22 00:10

Thor