How can I output subprocess script to GUI?
The minimal change for your script to do that:
from tkinter import *from tkinter import messageboxtop = Tk()top.title('RAID Status')top.geometry("250x160")def raidStat(): import subprocess myproc = subprocess.run(['./raidScripts/mdadmRaid.py'], stdout=subprocess.PIPE) messagebox.showinfo("Result", myproc.stdout)button1 = Button(top, text = "Check Status", command = raidStat)button1.grid(row=1,column=0)top.mainloop()
Note that we now redirect stdout
to subprocess.PIPE
and use stdout
attribute of created process object to access its content. Starting with Python 3.7 you can just call subprocess.run()
with capture_output=True
instead of dealing with stdout
(and/or stderr
).
As is in your code, the script output was not touched and all by Python. That is the reason why you could see it on the console, but could not access it to display it in your GUI.