0

Suppos there are many matlab.exe running on a windows PC, I am trying to terminate all of them, except the one I am working on. I did the following:

curPID = feature('getpid')
%say curPID return 10000.
%then follow:
system('taskkill /F /FI "PID ne 10000" /IM matlab.EXE');
%the above works fine.

But since every time, when I run

curPID = feature('getpid')

in different matlab GUI or m-file, the value of curPID will change, so I tried to pass curPID to the system() function as below:

system('taskkill /F /FI "PID ne curPID"/IM matlab.EXE');
% or
system('taskkill /F /FI "PID ne str2num(curPID)"/IM matlab.EXE');

but they do not work.

How can I pass curPID to taskkill?

XAM
  • 21
  • 4

1 Answers1

3

You can use sprintf to format your call to sys:

curPID = feature('getpid');
syscall = sprintf('taskkill /F /FI "PID ne %u" /IM matlab.EXE', curPID);
system(syscall);
sco1
  • 12,154
  • 5
  • 26
  • 48