xmlwrite in script does not produce a file
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello community,
I encountered a strange problem using xmlwrite in a script.
I created a simple xml structure accoring to https://de.mathworks.com/help/matlab/ref/xmlwrite.html?searchHighlight=xmlwrite&s_tid=doc_srchtitle
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
댓글 수: 0
답변 (1개)
Nick Trajkovski
2019년 1월 30일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!