A: 

I think it could be to do with different C runtimes. I know you can't pass file descriptors between different C runtimes - Python is built with MSVC (you will need to check which version) - so you could try to make MinGW build against the same C runtime - I think there is options to do this in MinGW like -lmsvcrt80 (or whichever is the appropriate versions) but for licensing reasons they can't distribute the libraries so you will have to find them on your system. Sorry I don't have any more details on that for now, but hopefully its a start for some googling.

A simpler way would be to just do it all in Python... just make a class which exposes a write and perhaps flush method and assign it to sys.stdout. Eg for a file you can just pass an open file object - it's probably straightfoward to do a similar thing for your pipe. Then just import it and sys and set sys.stdout in a PyRun_SimpleString.

thrope
Thanks for the reply!I'm sorry, I'm not sure I quite follow the thing with different runtimes... I tried:gcc -o std.exe std.c -Ic:/dev/include/python2.6 -l python26 -l msvcr90but then it crashes with "The application failed to initialize properly (0x80000003)."Also, I don't have MSVC - could this be it? That I need msvcrt.lib from VC2008 (IIRC this was used for Python 2.6)? In MinGW I have several libmsvc*.a...
EcirH
It's more involved than that to link against it with mingw but I'm afraid I don't have more details. It might be easiest to use the same microsoft compiler as Python used (I think visual studio 2008).
thrope
Or build Python yourself with MinGW - but no idea how easy that would be either.
thrope
Only thing I can find is ths: http://www.mail-archive.com/[email protected]/msg00285.html
thrope
Also this http://mail.python.org/pipermail/python-dev/2007-November/075473.html
thrope
I think I read somewhere (Python bug tracker) that building Python with MinGW is fairly difficult. Thanks for the links, though! I read them and I believe I have to read them once more, and once more, ...
EcirH
Visual Studio 2008 Express edition is free - I think it would be much easier. Easier still would be just doing the stdout redirection in Python as I mentioned so you wouldn't have to pass a file handle from c to python - but I don't know if you need C and Python stdout going to the same place.
thrope
PyRun_SimpleString('import sys;f = open('out.log','w');sys.stdout,sys.stderr= f,f')
thrope
I would like to collect all the output to a memory buffer, instead of a file, so I can process it later. I hoped I wont need to install VS2008 just for this but yes, this is an option too. But now that I look at your code, it might be possible to pass a file object to Python, redirect stdio as you wrote and when PyRun_SimpleString() finishes, read that file. Of cource, the best thing would be if Python worked with MinGW so I'll try in that direction a bit more. Thanks a lot for the help!
EcirH
...read that file-like object.
EcirH