I want to exec the command docker ps -q
using python os.system
function and then get its output to use it to create xml text node.
I tried xml.createTextNode(os.system("docker ps -q")
:
6 from xml.dom import minidom
7 import os
8
9 xml = minidom.Document()
10
11 rootElem = xml.createElement('containers')
12
13 dataElem = xml.createElement('data')
14
15 idElem = xml.createElement('id')
16 idElem.appendChild(xml.createTextNode(os.system("docker ps -q")))
But it gives me this error:
File "scriptCreateXML.py", line 16, in <module>
idElem.appendChild(xml.createTextNode(os.system("docker ps -q")))
File "/usr/lib/python3.6/xml/dom/minidom.py", line 1658, in createTextNode
raise TypeError("node contents must be a string")
TypeError: node contents must be a string
I expect the output of this
<?xml version="1.0" ?>
<containers>
<data>
<id>some id</id>
</data>
</containers>