MATLAB: How to kill a system process which is frozen

gagenetic algorithmkill exekill system spawned processsystemtaskkill

I'm working on some genetic algorithm optimisation code which interfaces with Xfoil for the analysis, using a system() command to run Xfoil. Sometimes Xfoil freezes (maybe due to a "bad" aerofoil shape), and this halts the entire optimisation process. I've added a simple timer based "kill exe" callback function, which is designed to kill the Xfoil exe run after a certain amount of time – this should give any "good" run a chance to finish, and should close any "bad" run. However, the callback function is not able to be called while Xfoil is running. It appears that even though the timer delay has ended and the TimerFcn() is triggered, Matlab cannot process the "kill exe" callback function while a system process is running.
So basically I can't kill the frozen system process. Anyone have any way around this?

Best Answer

You can use .Net System.Diagnostic.Process to run it. This way you will also be able to terminate the program.
if true
process = System.Diagnostics.Process();
process.StartInfo.FileName = 'java.exe';
process.StartInfo.Arguments = 'some args';
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.CreateNoWindow = false;
process.Start();
processisrunning = ~process.HasExited;
end
You can use the following command to kill the exe.
if true
process.Kill();
end