Launching external program from matlab
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
partha das
le 17 Août 2016
Réponse apportée : Dale Roach
le 29 Avr 2020
I am launching an external program from my Matlab code (on windows) using "system" command. My issue is that when i launch it this way, matlab will wait for the external program to close before it continues, which i don't want. Any solution to this?
0 commentaires
Réponse acceptée
Thorsten
le 17 Août 2016
Before you load the .mat file you can wait until the file exists
while ~exist('yourmatfile.mat', 2); end
2 commentaires
Walter Roberson
le 22 Août 2016
In order for that to work properly, you would need some way of telling the Dymola window what commands you want to execute at the start, and you would need some way of sending it new commands. You would also need some way of finding it what it is doing, because you would not be able to "queue" commands for it .
In order to be able to send another process commands dynamically, you need to use one of the following technologies:
1) process open, unix popen(), MS Windows _popen() . This is not designed for the case where commands must be given by pressing keys or clicking on buttons: this is for the case where commands can be given by an input stream of bytes and results retrieved by an output stream of bytes. There is a File Exchange contribution for doing popen(), but I/O can only happen in one direction for it, but your case probably needs I/O in both directions
2) TCP (or UDP). This requires that the program be designed to accept connections and receive commands and send results. It has the advantage of being fully supported in the Instrument Control toolbox and as well there is a File Exchange contribution "tcpudpip". This is more general than popen() but requires specific programming to support, and that probably does not exist in your case.
3) ActiveX / COM. This requires that the program be designed for it, and is effectively only an option for MS Windows.
4) Java Robot class. This is the most flexible in terms of sending keystrokes and mouse clicks, but it can get difficult to retrieve information.
Plus de réponses (3)
Dale Roach
le 29 Avr 2020
If you want to launch an application and don't want MATLAB to wait for it to close before returning control to your script, use the "start" command. Here's an example:
system('start notepad.exe testfile.txt');
Here I've launched notepad and told it to open the file testfile.txt. When you use the "start" command, it returns control to the system right away, so your scirpt can continue to run.
0 commentaires
KSSV
le 17 Août 2016
I guess you are running the program via command prompt...why dont you exit the program at command prompt itself, so that MATLAB can come out of system?
4 commentaires
Walter Roberson
le 17 Août 2016
... remove the & so that system() waits for the program to end?
If you cannot continue the MATLAB program until the .mat file is generated, then the only advantage of not using & is that you would be able to implement a Quit / Cancel button for impatient users.
Voir également
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!