Pablo SAILLY
Pablo SAILLY

Reputation: 33

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

Upvotes: 1

Views: 507

Answers (1)

Shashankh_
Shashankh_

Reputation: 168

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!

Upvotes: 1

Related Questions