How to close other program that matlab calls

I am using MATLAB to write text files that are executed by another program, MODTRAN. My program calls MODTRAN and runs, but it does not close the program; in fact, I must click yes for the program to close. This is coming to be a huge problem because I am going to be running a loop with at least 3000 cycles, and I can't have the screen pop up 3000 times and click yes all those times.
This is the code I use to call MODTRAN:
system('cd C:/users/.../mod5_64/ && start Mod5.2.0.0_cons.exe');
Attached is the screen that I see. The program will continue to run even if I don't click anything, so I will have many pop ups and it will probably crash my computer.
Is there a way for to code something in matlab that will either close this MODTRAN when it is done, or click yes when it asks?
Thank you!

 Accepted Answer

Can it be run as a COM server? If so, use ActiveX to launch it and shut it down. I've attached an ActiveX demo for Excel.
Or you can use my attached program to find the process in the task list and use system() and taskkill to forcibly kill it.

3 Comments

Thank you. I couldn't figure out how to get run modtran with ActiveX. I used your code to find modtran in the task list. My question is, is there a way to only kill it when modtran is done with the process? The task list says modtran is still running as long as the window i attached above is still open. I want to be able to monitor when the dialog box appears and I want to have matlab choose "yes." Is that possible?
I'm not sure. If you can get the CPU time it uses and monitor that, and if it hits zero for a while then maybe you can assume it's done, but maybe not. There is nothing where an app tells the operating system "I'm done now and I'm idle" so I think that monitoring the CPU time it's using, if that is even possible, which I don't know, is the only way.
It is possible to monitor the cpu-usage with PsList, which is free at Sysinternals.
str = evalc( 'system( PsList name/PID )' );
Better resolution and easier to parse than TaskList

Sign in to comment.

More Answers (1)

per isakson
per isakson on 28 Feb 2014
Edited: per isakson on 28 Feb 2014
If on Windows and you don't find any solution. Last resort is the DOS command taskkill. If you run several MODTRN simultaneously then you must know which to kill.

Tags

No tags entered yet.

Asked:

Sam
on 28 Feb 2014

Commented:

on 1 Mar 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!