2

我正在使用这个库来解析我的 xml:

import xml.etree.cElementTree as xml

解析器的 xml 输入是以下输出subprocess.Popen

XMLFile = subprocess.Popen(xml_command,shell=True,stdout=subprocess.PIPE, executable="/bin/ksh").communicate()[0]
root = xml.XML(XMLFile)

我收到此错误:

IOError: [Errno 36] File name too long: ' <?xml version=\...'

但是,当我传递从与xml_command文件相同的命令生成的 xml 时,它工作得非常好:

root = xml.parse("/home/test.xml")
4

2 回答 2

0

尝试这个:

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)

使用 python 2.6.6

将 subprocess.Popen 调用的输出存储在字符串中

于 2016-06-01T13:17:06.043 回答
-1

尝试这个

from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
于 2014-06-19T15:48:14.987 回答