TextCtrl as subprocess pipe

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

TextCtrl as subprocess pipe

Ondřej Vaverka
Hello all,

I am quiet newbie in the wxPython and I would like to ask you for your help and advice in this issue... I am trying to redirect standard/error outputs of some child process into the TextCtrl widget while parent GUI of this process is still running and waiting for child process to finish.
The subprocess module is used for child process spawning. Here is simplified script:

import subprocess as sp

...

rtc
= wx.TextCtrl(self.m_panel6, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.TE_DONTWRAP|wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2 )

...

proc
= sp.Popen(["avrdude.exe"] + args, stdout=rtc, stderr=rtc)

while proc.is_alive:
    wx
.Yield()
    proc
.communicate()

...

But it doesn't work and exception is thrown:

File "C:\Programs\Python27\lib\subprocess.py", line 382, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File "C:\Programs\Python27\lib\subprocess.py", line 531, in _get_handles
    c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
AttributeError: 'TextCtrl' object has no attribute 'fileno'

I already tried redirect stdout (sys.stdout) and stderr (sys.stderr) globally in application and it really redirects all print("...") messages into TextCtrl widget, but not output of process spawned by subprocess module...
Main target is to do simple GUI wrapper around awesome avrdude tool. But I am stuck at this point. Is there way how to use TextCtrl widget as subprocess pipe on MS Windows platform? Or another suitable way?




--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.