title: How can I script GNU Screen to start with a program running inside of it so that it does not exit the session on program completion?
body: <p>How can I script GNU Screen to start with a program running inside of it so that it does not exit the session when the program completes? </p>
  
  <p>I want to run an interactive program as a daemon, if I manually start screen and then launch this program inside of it everything works just as I want.  If the program exits or crashes the screen session remains and I can go look at it to see what just happened.  However, if I start the program with a simple screen launch then it does run inside of screen but when the program exits the screen session ends and any output from the program is lost.  </p>
  
  <p>So <code>screen –dmS serverName serverApplication</code> does not work for my scenario.  I did think about making a script which launches the program I want to run &amp; then sleeps forever, I could then launch the script at the same time as screen and should get the effect I am after but it seems rather an untidy way to do things and I am sure there must be something more elegant.  </p>
  
  <p>I have read quite a few screen tutorials and trawled through the man page but nothing leaps out at me as the right way to do this.  I did try –X but that is for screen commands, not for running commands inside the screen session... Any suggestions will be very much appreciated; I am even happy to use something other than GNU Screen if there is a better tool for use in scripting but please give me an example where possible.  </p>
  
  <p>(Side note:  The two things I will be running with this are a minecraft_server and a mythtv_backend.  My plan was to launch these from a chron job at boot via some ruby/bash script)</p>