简体   繁体   中英

how do I read the output of an external program while it is running in python

I'm trying to make a bot that controls a minecraft server and I've managed to make start and send commands to the server, however I can't get the output of the server while it is running what I have now will only send me the output after the server is terminated kind of like a log.

process = subprocess.Popen(executable,stdin=PIPE,stdout=PIPE, text=True)
out, err = process.communicate()
print(out)
print(err)

I would like to be able to use that server information to create a console

By looking at your project I think you mean to get the console/logs? anyway if that is your doubt.

here is the answer

while True:
    with open("XXXX\logs\latest.log","r") as f:
        console = f.read()
        await ctx.send(console)

Lemme know if this gives you an error or you have additional doubts!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM