Search code examples
pythonmingwstdoutdistutilsstderr

Catching error output from distutils using mingw


I'm using distutils to compile C code via a python script. If things go wrong, I want to be able to catch the error output. To this end, I've redirected stdout and stderr into temporary files before running the setup() command (you need to use os.dup2 for this).

On linux, it works fine. On windows + mingw I get some really weird behaviour:

  • Without trying to capture, stdout and stderr are both written to the command prompt.
  • When I try to capture, stdout works fine but the output to stderr disappears.

Does anybody understand what's going on here?


Solution

  • Woops.

    It turns out this was something really simple: capturing stdout and stderr output was working just fine, but the particular error message I was looking to catch (which was windows specific) wasn't part of the printed output but the error message of the raised SystemExit exception.

    Big waste of time :(