I am trying to run an external program from matlab as part of an optimization problem. My issue is that sometimes my external program will run into numerical issues and hang, so that the optimization will run forever and not finish. Currently I am using the following code to set a time limit on my program such that if it runs longer than a certain time, I know that it will not finish so I kill it and the optimization keeps going.
!taskkill -f -im myprg.exe
So if the program runs longer than n seconds, it stops. The only issue I have is that it pops up a new window every time I call my program and makes it very difficult to keep working on anything else on my computer. My question is if there is any way to have the matlab script keep running while also having my external program running within matlab. I know I can remove the '&' and it won't pop up a new window, but then I have to wait for the program to finish before the script can continue, so if my program hangs, I need to kill the entire optimization.
I have also tried using
system('start /b path_to_my_prg\myprg.exe');
to have it run completely in the background but have run into other issues since I cannot keep track of what the program is doing at all. So if there is another issue I won't know about it until the optimization ends in a number of hours or I kill it.
I do not have access to the source code for my .exe so I cannot make any changes within the program itself.
So is it possible to to have the matlab script keep running as with '&' but keep the program running within the command window as without '&'?