Launching external program from matlab
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Thorsten
il 17 Ago 2016
Before you load the .mat file you can wait until the file exists
while ~exist('yourmatfile.mat', 2); end
2 Commenti
Walter Roberson
il 22 Ago 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.
Più risposte (3)
Dale Roach
il 29 Apr 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 Commenti
KSSV
il 17 Ago 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 Commenti
Walter Roberson
il 17 Ago 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.
Vedere anche
Categorie
Scopri di più su Data Import and Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!