![](/img/trans.png)
[英]How should a Python file be written such that it can be both a module and a script with command line options and pipe capabilities?
[英]how to pipe a python script to a command (boost::program::options)
我试图将(在Windows中)python文件的输出重定向到使用boost :: program :: options创建的命令的stdin,如下所示:
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中的文件obejct的方法close()
需要使用缺少的这个描述符。
可能的解决方案可能是这样的: https : //superuser.com/questions/452763/how-to-pipleline-stderr-in-cmd-exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.