-
Notifications
You must be signed in to change notification settings - Fork 3
/
server_try.py
35 lines (31 loc) · 1.05 KB
/
server_try.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import subprocess
def printStdoutLog(process):
#print stdout
print("Outputs: ")
while True:
line = process.stdout.readline()
if not line:
break
print(line.decode('utf-8'))
def printStderrLog(process):
print("Errors: ")
while True:
line = process.stderr.readline()
if not line:
break
print(line.decode('utf-8'))
def runJavaProgram(programName, arguments):
command = ["java", programName] + arguments
# run the Java program
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# wait for the Java program to finish
print("Waiting for",programName, "to finish")
process.wait()
# check the return code to see if the java process completed successfully
if process.returncode != 0:
print(programName,"failed with error code: ", process.returncode)
printStderrLog(process)
printStdoutLog(process)
else:
print(programName,"finished successfully")
printStdoutLog(process)