Launching external program from matlab
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (3)
Walter Roberson
el 17 de Ag. de 2016
3 votos
Add "&" to the end of the command line.
Dale Roach
el 29 de Abr. de 2020
1 voto
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.
KSSV
el 17 de Ag. de 2016
0 votos
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 comentarios
partha das
el 17 de Ag. de 2016
Editada: Walter Roberson
el 17 de Ag. de 2016
Walter Roberson
el 17 de Ag. de 2016
Add "&" to the end of the command line.
command = 'autoMassLinearization_IO_Modell_temp.mos &';
You should also be considering redirecting input and output and standard error, even if only to /dev/null
command = 'autoMassLinearization_IO_Modell_temp.mos </dev/null >/dev/null 2>&1 &';
The above would produce an immediate End of File if the external program tried to read from the user (there is no connection by which it could get the input when you use &), and it throws away all output and error messages (you don't want them mixed in with the command window output of MATLAB if you have continued on with your MATLAB session.)
partha das
el 17 de Ag. de 2016
Editada: partha das
el 17 de Ag. de 2016
Walter Roberson
el 17 de Ag. de 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.
Categorías
Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!