jahil
jahil

Reputation: 426

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?

Upvotes: 17

Views: 24392

Answers (2)

Thor
Thor

Reputation: 47089

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.

Upvotes: 36

Eslam Saber
Eslam Saber

Reputation: 519

first create new session :

screen -dmS [session_name]

then attach command or script to run in session created :

screen -x [session_name] [script.sh]

Upvotes: 2

Related Questions