I am trying to get all output from child process in real time. I use spawn for creating child process but I am confused what I should send for pattern parameter in expect function. Actually I don't understand why it's not an optional parameter. I don't know if I should use send(), child doesn't need input. I'm just trying to write output to GUI. Anyway here's the code
pro=pexpect.spawn('python tx.py')
while True:
self.textEdit(pro.expect(['\n'])
edit: I managed to get some output
self.pro=pexpect.spawn('python tx.py',logfile=file('mylog.txt','w'))
self.pro.logfile_read = sys.stdout
while(self.pro.isalive()):
try:
self.textEdit.append(self.pro.read_nonblocking(size=100))
except pexpect.TIMEOUT:
self.pro.close(True)
except pexpect.EOF:
break
time.sleep(1)
I don't still get it. If I use read_nonblocking it still blocks main process, if I don't use it , logfile doesn't get updated so I have no output. Any idea what's wrong here?