import subprocess, string, time
args = 'java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui'.split()
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
thetime = time.time()
print thetime
#Watch and interface with the server
while(True):
if time.time() >= thetime + 5:
thetime = time.time()
p.stdin.write("say Saving...\n")
time.sleep(1)
p.stdin.write("save-all\n")
p.stdin.write("say Map saved.\n")
time.sleep(0.1)
p.stderr.readline()
log = p.stderr.readline()
words = log.split()
print log.strip()
time.sleep(0.2)
print 'Script shutdown complete!'