1

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

Community
  • 1
  • 1
Hobit Lai
  • 11
  • 3
  • related: [Display realtime output of a subprocess in a tkinter widget](http://stackoverflow.com/q/15362372/4279) (look at the code examples in the comments--if something is unclear; ask) – jfs Oct 29 '16 at 10:02
  • it looks like XY-problem: ["how to run a sudo command from python"](http://askubuntu.com/q/155791/3712) is a different question. – jfs Oct 29 '16 at 10:05

0 Answers0