![](/img/trans.png)
[英]Python, running a subprocess and read output and not hanging the program
[英]how do I read the output of an external program while it is running in python
我正在嘗試制作一個控制我的世界服務器的機器人,並且我已經成功啟動並向服務器發送命令,但是在服務器運行時我無法獲得服務器的 output 我現在只會發送我在服務器終止后的 output 有點像日志。
process = subprocess.Popen(executable,stdin=PIPE,stdout=PIPE, text=True)
out, err = process.communicate()
print(out)
print(err)
我希望能夠使用該服務器信息來創建控制台
通過查看您的項目,我認為您的意思是獲取控制台/日志? 無論如何,如果這是您的疑問。
這是答案
while True:
with open("XXXX\logs\latest.log","r") as f:
console = f.read()
await ctx.send(console)
讓我知道這是否會給您帶來錯誤或您還有其他疑問!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.