I'm trying to make a basic panel on which I can manage my Minecraft servers. To do that I need to run a shell script and copy its output while it's still running. From what I've seen in the docs for Popen
all read methods wait for the process to finish before returning any output. This is the code I'm trying with right now. Is there any way to start a process in the background and copy its output before the process has terminated?
shell = subprocess.Popen("./start.sh", shell= True, stdout=subprocess.PIPE)
def getconsole() -> str:
stdout = shell.communicate(timeout=1)[0]
string = stdout.decode("utf-8")
return string