Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:47:36+00:00 2026-05-23T19:47:36+00:00

How can I script GNU Screen to start with a program running inside of

  • 0

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?

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.

So screen –dmS serverName serverApplication does not work for my scenario. I did think about making a script which launches the program I want to run & 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.

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.

(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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:47:36+00:00Added an answer on May 23, 2026 at 7:47 pm

    First, you’ll want to start a daemon screen session just running your default shell:

    $ screen -dmS "serverName"
    

    Then, send your command to that shell using screen’s stuff in combination with -X:

    $ screen -S "serverName" -p 0 -X stuff "serverApplication$(printf \\r)"
    

    The -p is important for telling screen into which window within that session to stuff the command. In this case, it’s the only available window, 0, but if you don’t specify that, for some odd reason your command will go nowhere. The $(printf \\r) sends a ‘Return’ keystroke. A regular \n might work in its place, but I’ve read that’s shell-dependent. The newline character does not work in bash; I can vouch for that.

    Here’s another cool trick. If you want to then make another screen window within that session, you can:

    $ screen -S "serverName" -X screen
    

    Now you can send commands to that one using the same syntax as above, but with -p 1. Lots of fun.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a script that can select all text references to URLs
Does anyone have an example of script that can work reliably well across IE/Firefox
I want to write a sh/bash script that can determine whether a particular directory
How can I script a bat or cmd to stop and start a service
I have a PHP script that can encode a PNG image to a Base64
How do I have a Python script that can accept user input and how
I've got a nice power-shell driven post-build script that does some magic mumbo-jumbo for
I've found a PowerShell script that can change the desktop wallpaper of my Windows
I have a ipy script that can be called either from an embedded console
I realize you can script Microsoft Office apps, but I'm looking for something more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.