I have the following python script:
import shlex
import subprocess
from datetime import datetime,timedelta
import os
import sys
import xml.etree.ElementTree as ET
time = (datetime.now()- timedelta(hours=6)).strftime('%Y-%m-%dT%H:%M:%S')
#print time
path = sys.argv[1]
os.chdir(path + '/src/MarketplaceWebServiceOrders/Samples')
cmd = "php -f ListOrders.php %s > response.xml" %(time)
print cmd
args = shlex.split(cmd)
p = subprocess.Popen(args)
p.wait()
respFile = open("response.xml")
respFile.close()
tree = ET.parse(path + '/src/MarketplaceWebServiceOrders/Samples/response.xml')
root = tree.getroot()
I want to redirect the output of the subprocess to the file response.xml
. In the next step I want to parse the contents of response.xml. So it must be closed before we can parse. But, after execution
response.xmlends up being blank and I'm getting error in the line
tree = ET.parse(…)`. I also tried:
respFile = open("response.xml","w")
cmd = "php -f ListOrders.php %s > %s" %(time,respFile)
print cmd
args = shlex.split(cmd)
p = subprocess.Popen(args)
p.wait()
respFile.close()
This doesn’t work either. Please can someone help