xmlwrite in script does not produce a file

4 visualizaciones (últimos 30 días)
S vC
S vC el 24 de En. de 2019
Respondida: Nick Trajkovski el 30 de En. de 2019
Hello community,
I encountered a strange problem using xmlwrite in a script.
Below is the part which creates the xml file.
docNode = com.mathworks.xml.XMLUtils.createDocument('testsuite');
testsuite = docNode.getDocumentElement;
testsuite.setAttribute('name',Functionname);
testsuite.setAttribute('disabled',num2str(NumberOfDisabledTests));
testsuite.setAttribute('errors',num2str(NumberOfErrors));
testsuite.setAttribute('failures',num2str(NumberOfFailures));
testsuite.setAttribute('tests',num2str(NumberOfTests));
%Create Test case element
for idx = 1:length(TestfallNamenListe)
test_node = docNode.createElement('testcase');
test_node.setAttribute('name',TestfallNamenListe{idx});
test_node.setAttribute('classname',Functionname);
test_node.setAttribute('status',StatusListe{idx});
docNode.getDocumentElement.appendChild(test_node);
if strcmp(FailureTextListe{idx},'')
% do not add a failure node
else
failure_node = docNode.createElement('failure');
failure_text = docNode.createTextNode(FailureTextListe{idx});
failure_node.appendChild(failure_text);
test_node.appendChild(failure_node);
end
if strcmp(ErrorTextListe{idx},'')
% do not add a failure node
else
error_node = docNode.createElement('error');
error_text = docNode.createTextNode(ErrorTextListe{idx});
error_node.appendChild(error_text);
test_node.appendChild(error_node);
end
end
% Write to file
disp('Write XML file.');
xmlFilename = ['..\', 'Testresult_', Functionname, '.xml'];
xmlwrite(xmlFilename,docNode)
disp('Done.');
quit
Executing the script from cmd.exe with
matlab -automation -r "run('ABSPATHTOFOLDER\software\model\startup.m');run('ABSPATHTOFOLDER\AddCarnotPaths.m');run('ABSPATHTOFOLDER\software\test\JenkinsTests')" -logfile ABSPATHTOFOLDER\intermediate\TestLog.log -wait
does not create a xml file.
The strange thing is that if I comment out
quit
and execute
xmlwrite(xmlFilename,docNode)
manually in the command line window of Matlab I get the xml file with the correct content.
This means that programatically everything seems to be ok.
Does anyone have a explanatoin why xmlwrite per automation switch does not create the expected file?
Thanks in advance
Best regards

Respuestas (1)

Nick Trajkovski
Nick Trajkovski el 30 de En. de 2019
Hi,
The issue occurs since the quit command in your script closes the MATALB session so any scripts following the quit command do not execute. I commented out the quit command and instead added it to the list of the command line parameters:
matlab -automation -r "run('ABSPATHTOFOLDER\software\model\startup.m');run('ABSPATHTOFOLDER\AddCarnotPaths.m');run('ABSPATHTOFOLDER\software\test\JenkinsTests'); quit;" -logfile ABSPATHTOFOLDER\intermediate\TestLog.log -wait
This sholud fix the issue you are running into.

Etiquetas

Productos


Versión

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by