python - 使用 mingw 捕获 distutils 的错误输出

标签 python mingw stdout distutils stderr

我正在使用 distutils 通过 python 脚本编译 C 代码。如果出现问题,我希望能够捕获错误输出。为此,我在运行 setup() 命令之前将 stdout 和 stderr 重定向到临时文件(您需要为此使用 os.dup2)。

在linux上,它工作得很好。在 windows + mingw 上我得到了一些非常奇怪的行为:

  • 在不 try catch 的情况下,stdout 和 stderr 都会写入命令提示符。
  • 当我 try catch 时,stdout 工作正常,但 stderr 的输出消失。

有人明白这是怎么回事吗?

最佳答案

糟糕。

事实证明这非常简单:捕获 stdout 和 stderr 输出工作得很好,但是我想要捕获的特定错误消息(这是 Windows 特定的)不是打印输出的一部分,而是错误消息引发的 SystemExit 异常。

浪费时间:(

关于python - 使用 mingw 捕获 distutils 的错误输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24900200/

相关文章:

python - 如何在 Google App Engine 中动态更改 python 应用程序的日志记录级别?

python - 如何判断python是mingw还是官方build?

c - Winternl.h : No such file or directory

c++ - Gtkmm 程序编译正常但崩溃 - Windows XP

c# - 使用 STDOUT 打印语句将控制台附加到 C# Windows 应用程序

C 编程 - freopen 附加一个 ?到文件名

python - 使用 Paramiko 执行的命令不会产生任何输出

python - 如何测试 windowFlags 中是否设置了 WindowStaysOnTopHint 标志?

python - django/BeautifulSoup 字典错误

python - 了解街道地址的 Pyparsing