I'm developing a python script that calls and executes a csh script. For this I'm using the pexpect.spawnu that calls the script and sends an option every time that csh script asks for it.
My problem is that I need to redirect the stdout of csh script to a tkinter text widget in real time but at this moment the information is written to the text widget only when child is closed.
I've already tried to redirect all child.logfile to the stdout and the stdout to the text widget but even so the information is written only when child is closed.
child = pexpect.spawnu('script_name'+ param1 + ' '+ param2, timeout=None)
child.logfile = sys.stdout
for line in child:
self.text1.insert(tk.INSERT, line) # this will be inserted only when child is closed
if 'option' in line:
child.sendline(opt1)
child.close()
I'm trying to put the child.logfile to insert the stdout directly in the text widget but I still cannot.
Thanks.
[EDIT]
See the solution in the comment.
It seems the text widget was being updated only when class finishes the execution. After the insert I only need to update the text widget to view the information in real time like:
child = pexpect.spawnu('script_name'+ param1 + ' '+ param2, timeout=None)
child.logfile = sys.stdout
for line in child:
self.text1.insert(tk.INSERT, line)
self.text1.update() # update the information in the text widget
if 'option' in line:
child.sendline(opt1)
child.close()
It's solved, thanks!