Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Python中分析subprocess.Popen输出中的xml_Python_Xml Parsing_Subprocess_Xml.etree_Celementtree - Fatal编程技术网

无法在Python中分析subprocess.Popen输出中的xml

无法在Python中分析subprocess.Popen输出中的xml,python,xml-parsing,subprocess,xml.etree,celementtree,Python,Xml Parsing,Subprocess,Xml.etree,Celementtree,我正在使用此库解析我的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 3

我正在使用此库解析我的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=\...'
试试这个

from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
试试这个

from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
试试这个:

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

试试这个:

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


您正在将整个xml文件作为文件名传递,所以您遇到了这个错误。请找出如何获取文件名并将其传递到
xml.xml
XMLFile
是xmldata而不是XMLFile这就是为什么我将xml.xml与XMLFile一起使用,并将xml.parse与文件路径一起使用。是否有可能
xml\u命令
以某种方式保存xml数据,而错误来自
subprocess.Popen()
invocation?我建议在这两行之间放一条调试语句,只是为了再次检查您是否知道异常来自何处-
IOError
是一种几乎可以来自任何地方的通用异常。您将整个xml文件作为文件名传递,所以您遇到了这个错误。请找出如何获取文件名并将其传递到
xml.xml
XMLFile
是xmldata而不是XMLFile这就是为什么我将xml.xml与XMLFile一起使用,并将xml.parse与文件路径一起使用。是否有可能
xml\u命令
以某种方式保存xml数据,而错误来自
subprocess.Popen()
invocation?我建议在这两行之间放一条debug语句,只是为了再次检查您是否知道异常来自哪里-
IOError
是一种几乎可以来自任何地方的通用异常。