[~,tasks] = system('tasklist/fi "imagename eq Excel.exe"');
tasks=sscanf(tasks,'%s');
exe=strfind(tasks,'.EXE');
console=strfind(tasks,'Console');
pid_before=zeros(1,size(exe,2));
for i=1:1:size(exe,2)
pid_before(1,i)=convertCharsToStrings(tasks((exe(i)+4):(console(i)-1)));
end
[~,tasks] = system('tasklist/fi "imagename eq Excel.exe"');
tasks=sscanf(tasks,'%s');
exe=strfind(tasks,'.EXE');
console=strfind(tasks,'Console');
pid_after=zeros(1,size(exe,2));
for i=1:1:size(exe,2)
pid_after(1,i)=convertCharsToStrings(tasks((exe(i)+4):(console(i)-1)));
end
if size(pid_after,2)>size(pid_before,2)
command=['taskkill /f /PID ',mat2str(pid_after(1,end))];
system(command)
end
7 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_233113
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_233113
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_334264
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_334264
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_334272
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_334272
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_378934
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_378934
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_511057
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_511057
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_515016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_515016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_675700
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab#comment_675700
Sign in to comment.