Force Matlab to continue when stuck in busy mode?

39 visualizaciones (últimos 30 días)
Eddie Nilsson
Eddie Nilsson el 12 de Mayo de 2017
Comentada: José Daniel Hoyos Giraldo el 27 de Jul. de 2020
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 comentario
Rik
Rik el 12 de Mayo de 2017
Editada: Rik el 12 de Mayo de 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.

Iniciar sesión para comentar.

Respuestas (1)

Nagarjuna Manchineni
Nagarjuna Manchineni el 15 de Mayo de 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 comentarios
Satish Natarajan
Satish Natarajan el 21 de Sept. de 2017
Editada: Satish Natarajan el 21 de Sept. de 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 el 27 de Jul. de 2020
did u get the solution?

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by