I want to make a program that can execute jar files and print whatever the jar file is doing in my python program but without using the windows command line, I have searched all over the web but nothing is coming up with how to do this.
My program is a Minecraft server wrapper and I want it to run the
server.jar file and instead of running it within the windows command prompt I want it to run inside the Python shell.
First you have to execute the program. A handy function for doing so:
def run_command(command): p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) return iter(p.stdout.readline, b'')
It will return an iterable with all the lines of output.
And you can access the lines and print using
for output_line in run_command('java -jar jarfile.jar'): print(output_line)
import subprocess, as
run_command uses subprocess.