I'm trying to write a script to:
- Start a new
screen
session - Run some program or script within that new screen session
- Detach from the screen session, while the program from step 2 may still be running in there. If the program from step 2 finishes, immediately or later, the screen session should remain running (detached).
I have been trying all sorts of combinations with screen -X program
or screen -S somename
followed by program
followed by screen -D
, combining with -d
or -m
options which I find in related questions and answers but nothing works.
The closest I could get was this:
screen -S MySessionName -d -m myprogram
This launches a new screen session in the backgroun, running myprogram
.
Except as soon as myprogram
finishes (sometimes instantly) the screen session terminates, whereas I want to keep it running.
screen -S test -d -m myprogram
except the screen session terminates aftermyprogram
is finished. I'll add this in my post for completeness.