Effacer les filtres
Effacer les filtres

Force Matlab to continue when stuck in busy mode?

37 vues (au cours des 30 derniers jours)
Eddie Nilsson
Eddie Nilsson le 12 Mai 2017
Hello
In my code I have a line where I call an external program through the system command. That external program sometimes get stuck which in turn puts Matlab into 'busy' for forever. What I want is that when Matlab has been stuck on that line for more than let's say 3 second it should continue regardless if that line has been finished or not, is there any way to achieve this?
this is the line that get's stuck: [~,~] = system('cd /home/eddien && xfoil < foily.inp > xfoil.out');
Thanks in advance!
  1 commentaire
Rik
Rik le 12 Mai 2017
Modifié(e) : Rik le 12 Mai 2017
Judging by the command I see you are not on Windows. If you are on Linux, you can try out this suggestion on stackoverflow.
Edit: you could even use that line of code in a call to system.

Connectez-vous pour commenter.

Réponses (1)

Nagarjuna Manchineni
Nagarjuna Manchineni le 15 Mai 2017
You can append ' &' (ampersand) at the end of the command for executing the command and immediately return the exit status to MATLAB.
For example, you can use the following command:
[~,~] = system('cd /home/eddien && xfoil < foily.inp > xfoil.out &');pause(2);
And if you wanted to wait for a couple of seconds before returning back to the code you can use 'pause' command.
After that, you can get the control back to the MATLAB command prompt or the script/function.
For receiving the process ID after creating the process, append the above command with 'echo $!'. For example,
[status,cmdout] = system('cd /home/eddien && xfoil < foily.inp > xfoil.out & echo $!');pause(2);
The process ID of the above spawned process will be stored in the variable 'cmdout'.
If you wanted to kill the spawned process (launched using system command), then you need to use the kill command. For example,
>> system(['kill ' cmdout]);
  2 commentaires
Satish Natarajan
Satish Natarajan le 21 Sep 2017
Modifié(e) : Satish Natarajan le 21 Sep 2017
I executed your commands, but still xfoil.exe doesn't close if it goes into infinite loop. Is there any other way to force close xfoil.exe through Matlab within 30 seconds of the start of execution?
José Daniel Hoyos Giraldo
José Daniel Hoyos Giraldo le 27 Juil 2020
did u get the solution?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Low-Level File I/O 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!

Translated by