You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/mcwrap/mcwrap.py

46 lines
1.1 KiB

from __future__ import unicode_literals, print_function
import io
import os
import subprocess
import sys
import threading
def main():
os.chdir(os.path.expanduser('~/tmp'))
with open('eula.txt', 'w') as eula:
eula.write('eula=true\n')
jar = os.path.expanduser('~/tmp/minecraft_server.1.10.2.jar')
command = [
'java', '-Xmx2560M', '-Xmn128M', '-jar', jar, '-o', 'true', 'nogui'
]
print('Running pid={} command="{}"'.format(os.getpid(), ' '.join(command)))
minecraft = subprocess.Popen(
command, stdout=subprocess.PIPE, stdin=subprocess.PIPE
)
try:
stdout_buf = io.BytesIO()
stdout_thread = threading.Thread(
target=_tee, args=(minecraft.stdout, stdout_buf)
)
stdout_thread.run()
minecraft.wait()
return 1
except KeyboardInterrupt:
print('Terminating pid={}'.format(os.getpid()))
minecraft.terminate()
return 0
return 0
def _tee(stdout, tee_out):
for line in stdout:
print(line, file=sys.stdout, end='')
tee_out.write(line)
tee_out.flush()
if __name__ == '__main__':
sys.exit(main())