I'm a novice in python,and i have spend several hours searching solutions on stack overflow and found the closest one Issues intercepting subprocess output in real time
i try this one:
`enter code here` from threading import Thread
from queue import Queue, Empty
def readlines(process, queue):
while process.poll() is None:
queue.put(process.stdout.readline())
...
def startProcess(self):
self.process = subprocess.Popen(['./subtest.sh'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
self.queue = Queue()
self.thread = Thread(target=readlines, args=(self.process, self.queue))
self.thread.start()
self.after(100, self.updateLines)
def updateLines(self):
try:
line = self.queue.get(False) # False for non-blocking, raises Empty if empty
self.console.config(state=tkinter.NORMAL)
self.console.insert(tkinter.END, line)
self.console.config(state=tkinter.DISABLED)
except Empty:
pass
if self.process.poll() is None:
self.after(100, self.updateLines)
then i found that when subprocess.Popen(py script),it does work. but when i try
subprocess.Popen(C executable
),like this subprocess.Popen(["sudo","./xxx","/dev/ttyACMO"
]),it doesn't work