【发布时间】:2017-03-29 09:20:06
【问题描述】:
我正在尝试(在 Windows 中)将 python 文件的输出重定向到使用 boost::program::options 创建的命令的标准输入,如下所示:
python test.py | command.exe -s
test.py 只是打印文件的内容:
f = open('test.xml', 'r')
print f.read()
f.close()
如果我只执行 python 文件,它可以工作,但如果我尝试将它传递给另一个命令,它会失败并出现以下错误:
close failed in the file object destructor:
sys.excepthook is missin
lost sys.stderr
如果我尝试执行这个command.exe -s < test.xml 它工作正常,所以我猜是管道的问题。
有人知道发生了什么吗?
【问题讨论】:
-
您会收到此错误,因为当 CMD 创建管道时,它正在关闭 STDERR。并且不知何故,python中文件对象的
close()方法需要使用这个缺失的描述符。
标签: python c++ boost pipe boost-program-options