Redirecting STDIO/STDERR in an python embedded application

Karl Bellve Karl.Bellve at umassmed.edu
Mon Apr 2 16:51:55 EDT 2001


I am trying to redirect Pythons STDIO/STDERR within my application. Here
is the python code:

PyRun_SimpleString("class my_stdout:\n"
		   "    def write(self,string):\"
		   "         image.stdout(string)\n"
		   "import sys\n"
	           "sys.stdout = my_stdout()\n");

And here is the C++ code:

static struct _object *s_stdout(PyObject *self, PyObject *args)
{

	char *string = NULL;

	if (!PyArg_ParseTuple(args, "s" &string))
		return Py_None;
	/* some code

	return Py_None
}

The function s_stdout is being called but PyArg_ParseTuple is failing. I
believe it doesn't think there is a string in the "args" Object. When I
look at the "args" object, it claims it is a "string" but I don't
actually see any text associated with it, other than "string." Any
ideas?



-- 
Cheers,



Karl Bellve




More information about the Python-list mailing list