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=\...'

ただし、同じコマンドから生成された xmlxml_commandをファイルとして渡すと、完全に正常に動作します。

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 に答える