stderr, stdout, and errno 24
Dave Hansen
iddw at hotmail.com
Wed Jul 12 22:00:37 EDT 2006
On 12 Jul 2006 18:09:42 -0700 in comp.lang.python, "Wesley Henwood"
<wesleyhenwood at hotmail.com> wrote:
>To capture output from python scripts run from a C++ app I've added the
>following code at the beggening of the C++ app:
>
>PyRun_SimpleString("import grabber");
>PyRun_SimpleString("import sys");
>PyRun_SimpleString("class a:\n\tdef
>write(self,s):\n\t\tograbber.grab(s)\n");
>PyRun_SimpleString("import sys\nsys.stderr=a()\nsys.stdout=a()");
>
>Its hard to read that way, here's what it expands to:
>import grabber
>import sys
>class a:
> def write(self, s)
> grabber.grab(s)
Actually, that last line will more like
> ograbber.grab(s)
At least, if what you posted above is accurate...
It's not the question you asked, but if you want to make that easier
to read, you can do something like
PyRun_SimpleString("import grabber");
PyRun_SimpleString("import sys");
PyRun_SimpleString("class a:\n"
" def write(self,s):\n"
" grabber.grab(s)\n");
PyRun_SimpleString("import sys\n"
"sys.stderr=a()\n"
"sys.stdout=a()\n");
C++, like Python, will concatenate strings seperated only by
whitespace.
Regards,
-=Dave
--
Change is inevitable, progress is not.
More information about the Python-list
mailing list