hi all, I'm calling from Python a C dll that prints something in std output. I
would like to redirect this to a wxPython
control. How can I do that? It seems
that doing sys.stdout=wx.SomeControlWithWriteMethod(..) is not enough
hi all, I'm calling from Python a C dll that prints something in
std output. I
would like to redirect this to a wxPython
control. How can I do that? It seems
that doing sys.stdout=wx.SomeControlWithWriteMethod(..) is not enough
How are you calling the dll? If you are using POpen you can read from the dll's stdout pipe and then just set the text in the control you are using.
sys.stdout is for the running instance of Python's stdout not an external process like what would be coming from your dll.
Cody
Hello,
Are you talking about subprocess.Popen ? (or some other popen?)
I'm also interested in redirecting outputs from my dll to wxPython. I also would like to redirect to different wxcontrols for each of my threads.
Regards,
Mathias
···
On Tue, Sep 30, 2008 at 10:07 AM, m.prosperi@libero.it > <mailto:m.prosperi@libero.it> <m.prosperi@libero.it > <mailto:m.prosperi@libero.it>> wrote:
hi all, I'm calling from Python a C dll that prints something in
std output. I
would like to redirect this to a wxPython
control. How can I do that? It seems
that doing sys.stdout=wx.SomeControlWithWriteMethod(..) is not enough
How are you calling the dll? If you are using POpen you can read from the dll's stdout pipe and then just set the text in the control you are using.
sys.stdout is for the running instance of Python's stdout not an external process like what would be coming from your dll.
Cody
Hello,
Are you talking about subprocess.Popen ? (or some other popen?)
I'm also interested in redirecting outputs from my dll to wxPython. I also would like to redirect to different wxcontrols for each of my threads.
Regards,
Mathias
Shouldn't you be able to use subprocess's communicate() method to get its stdout/stderr? You'll probably have to poll for it though. Otherwise you'll probably just block wxPython's main loop. To actually write to a text control, I usually do something like this:
Shouldn't you be able to use subprocess's communicate() method
to get its stdout/stderr?
To what does "it" refer? AFAICT, there's only one process
involved (there is no sub-process). The OP is calling a
library function that's writing to the stdout/stderr file
descriptors. If he were running an external program, I can see
how one would use subprocess, but how do you use it to call a
library function?
On Unix, one could solve the OP's problem by creating a pipe or
two then fork()ing:
In the child process: attach the pipes to file descriptors 1
and 2, call the library function, then exit.
In the parent process: read the data from the "other" ends of
the pipes.
That assumes that the library function is doing something to
external object (files, sockets, whatever). If you're using
the library to manipulate internal data, then the above
approach won't work, since the child is running in a seperate
address space and results of the library call won't be visible
to the parent other than what comes through the pipe.
···
On 2008-09-30, Mike Driscoll <mike@pythonlibrary.org> wrote:
You'll probably have to poll for it though. Otherwise you'll
probably just block wxPython's main loop. To actually write to
a text control, I usually do something like this:
--
Grant Edwards grante Yow! I just had a NOSE
at JOB!!
visi.com
On 2008-09-30, Mike Driscoll <mike@pythonlibrary.org> wrote:
Shouldn't you be able to use subprocess's communicate() method
to get its stdout/stderr?
To what does "it" refer? AFAICT, there's only one process
involved (there is no sub-process). The OP is calling a
library function that's writing to the stdout/stderr file
descriptors. If he were running an external program, I can see
how one would use subprocess, but how do you use it to call a
library function?
Oops...looks like I mis-read someone's issue again. Sheesh! Don't mind me.