MATLAB: Does externally called .exe using the ‘system’ command freeze on the third call

external programsystem command

I have a Matlab script (R2011b) that calls and external compiled C# program. The C# program opens up a remote application, loads some data, and then saves that data. When I run the C# program from the cmd line it runs just fine and I can run it over and over again. However, when I run the program through Matlab withe the 'system' command it runs fine the first and second time but on a third time it hangs when it tries to save the data. Any suggestions on what might be going on here? I've tried calling the program through a batch file also and also tried compiling the Matlab code but the results were the same. Thanks in advanced for any suggestions.

Best Answer

While I don't know why Matlab is causing this issue when using the 'system' command, I did stumble across a working solution. Instead of using the 'system' command to call the .exe I instead us the Java runtime to make the call. Sample code below that seems to work (where 'executable' is the variable that contains the .exe string):
rt=java.lang.Runtime.getRuntime(); pr = rt.exec(['cmd /c start /wait ' executable]); pr.waitFor();
Related Question