2

I'm using this library to parse my xml:

import xml.etree.cElementTree as xml

The xml input to the parser is an output of 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:

root = xml.parse("/home/test.xml")
beresfordt
  • 5,088
  • 10
  • 35
  • 43
TuaimiAA
  • 973
  • 6
  • 15
  • 3
    You are passing the entire xml file as filename , so you are getting that error.Figure out how to get the filename and pass it to `xml.XML`.... – Srinivas Reddy Thatiparthy Feb 12 '13 at 08:46
  • `XMLFile` is xmldata not xmlfile – avasal Feb 12 '13 at 08:50
  • That's why I'm using xml.XML with XMLFile and xml.parse with the file path. – TuaimiAA Feb 12 '13 at 09:00
  • Is it possible that somehow `xml_command` ends up holding the XML data and the error comes from the `subprocess.Popen()` invocation? I would recommend putting a debug statement between the two lines just to double-check you know where the exception is coming from - `IOError` is the sort of generic exception which can come from almost anywhere. – Cartroo Feb 12 '13 at 15:19

2 Answers2

0

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

Store output of subprocess.Popen call in a string

Community
  • 1
  • 1
LAL
  • 480
  • 5
  • 13
-1

Try this

from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
Finch_Powers
  • 2,938
  • 1
  • 24
  • 34