How hard could it be
This commit is contained in:
parent
81f5be99aa
commit
670630bcdb
45
mcwrap/mcwrap.py
Normal file
45
mcwrap/mcwrap.py
Normal file
@ -0,0 +1,45 @@
|
||||
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())
|
Loading…
Reference in New Issue
Block a user