[英]Cannot parse xml from subprocess.Popen output in Python
I'm using this library to parse my xml: 我正在使用此库来解析我的xml:
import xml.etree.cElementTree as xml
The xml input to the parser is an output of subprocess.Popen
: 输入到解析器XML是的输出
subprocess.Popen
:
XMLFile = subprocess.Popen(xml_command,shell=True,stdout=subprocess.PIPE, executable="/bin/ksh").communicate()[0]
root = xml.XML(XMLFile)
I get this error: 我收到此错误:
IOError: [Errno 36] File name too long: ' <?xml version=\...'
However, when I pass the xml generated from the same command xml_command
as file, it works perfectly fine: 但是,当我传递从与文件相同的命令
xml_command
生成的xml时,它工作得很好:
root = xml.parse("/home/test.xml")
Try this: 尝试这个:
import xml.etree.cElementTree as xml
p = subprocess.Popen(xml_command, shell=True, stdout=subprocess.PIPE, executable="/bin/ksh")
text, err = p.communicate()
root = xml.fromstring(text)
with python 2.6.6 使用python 2.6.6
Store output of subprocess.Popen call in a string
将subprocess.Popen调用的输出存储在字符串中
Try this 尝试这个
from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.