Reputation: 43
I am making a python program that communicates with a minecraft server and tells it to start, stop, or any other commands. The program reads an email and executes the command given from the email. When the program enters the command to start the server, it freezes the python program until the minecraft server is stopped.
I have tried to have the program open a batch file that starts the server, but then I don't have any way of making the program turn it off, or type in commands, or read the console.
if data[0]+data[1]+data[2]+data[3]+data[4]+data[5] == 'start ':
comm = data.replace('start ','')
try:
mb = int(float(comm)*1024)
#calls the command to start the server
call('java -Xmx' + str(mb) + 'M -Xms' + str(mb) + 'M -jar server.jar nogui')
#program freezes here until server is stopped
except Exception:
call('java -Xmx1024M -Xms1024M -jar server.jar nogui')
print("started server")
elif data == "stop server" or data == "stop":
call('stop')
elif data[0]+data[1]+data[2]+data[3]+data[4] == 'call ':
comm = data.replace('call ','')
call(comm)
print("called command")
elif data[0]+data[1]+data[2] == 'op ':
comm = data
call(comm)
print("op player")
else:
print("not a command")
deletemail(mail,i)
print("deleted item")
I expected to see the program continue and respond to emails, but it froze instead. The program continued off normally after the server was stopped. I know this isn't an error, but is there a way to get the python program to continue while the server is running?
Upvotes: 2
Views: 122