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 3308694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:33:06+00:00 2026-05-17T21:33:06+00:00

I have a small script that launches and, every half hour, feeds a command

  • 0

I have a small script that launches and, every half hour, feeds a command to a java program (game server manager) as if the user was typing it. However, after reading documentation and experimenting, I can’t figure out how I can get two things:

1) A version which allows the user to type commands into the terminal windoe and they will be sent to the server manager input just as the “save-all” command is.

2) A version which remains running, but sends any new input to the system itself, removing the need for a second terminal window. This one is actually half-happening right now as when something is typed, there is no visual feedback, but once the program is ended, it’s clear the terminal has received the input. For example, a list of directory contents will be there if “dir” was typed while the program was running. This one is more for understanding than practicality.

Thanks for the help. Here’s the script:

from time import sleep
import sys,os
import subprocess


#  Launches the server with specified parameters, waits however
#  long is specified in saveInterval, then saves the map.


#  Edit the value after "saveInterval =" to desired number of minutes.
#  Default is 30

saveInterval = 30

#  Start the server.  Substitute the launch command with whatever you please.
p = subprocess.Popen('java -Xmx1024M -Xms1024M -jar minecraft_server.jar',
                     shell=False,
                     stdin=subprocess.PIPE);

while(True):

    sleep(saveInterval*60)

    #  Comment out these two lines if you want the save to happen silently.
    p.stdin.write("say Backing up map...\n")
    p.stdin.flush()

    #  Stop all other saves to prevent corruption.
    p.stdin.write("save-off\n")
    p.stdin.flush()
    sleep(1)

    #  Perform save
    p.stdin.write("save-all\n")
    p.stdin.flush()
    sleep(10)

    #  Allow other saves again.
    p.stdin.write("save-on\n")
    p.stdin.flush()
  • 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-17T21:33:07+00:00Added an answer on May 17, 2026 at 9:33 pm

    Replace your sleep() with a call to select((sys.stdin, ), (), (), saveInterval*60) — that will have the same timeout but listens on stdin for user commands. When select says you have input, read a line from sys.stdin and feed it to your process. When select indicates a timeout, perform the “save” command that you’re doing now.

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

Sidebar

Related Questions

I have a script that animates a small DIV popping up on the page.
I have a small script that I use to resize all of the images
I have this small script that shows a caption for a img when it
I have a small script that moves the frame head backwards and forwards depending
I have a small script that copies files to a list of remote machines.
I have a small script that use urllib2 to get contents of a site,
I have a small script that I am try to port to work for
I have this small script that sorts the content of a text file #
I have a problem with my index.php, i have this small script that decides
I have this small jquery script that does not work if I remove the

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.