【问题标题】:how to pipe a python script to a command (boost::program::options)如何将 python 脚本通过管道传输到命令(boost::program::options)
【发布时间】: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


【解决方案1】:

您收到此错误是因为当 CMD 创建管道时,它正在关闭 STDERR。而python中文件对象的方法close()需要使用这个缺失的描述符。

可能的解决方案可能是这样的: https://superuser.com/questions/452763/how-to-pipleline-stderr-in-cmd-exe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2018-08-18
    • 2015-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多