Force Matlab to continue when stuck in busy mode?

43 ビュー (過去 30 日間)
Eddie Nilsson
Eddie Nilsson 2017 年 5 月 12 日
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 件のコメント
Rik
Rik 2017 年 5 月 12 日
編集済み: Rik 2017 年 5 月 12 日
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.

サインインしてコメントする。

回答 (1 件)

Nagarjuna Manchineni
Nagarjuna Manchineni 2017 年 5 月 15 日
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 件のコメント
Satish Natarajan
Satish Natarajan 2017 年 9 月 21 日
編集済み: Satish Natarajan 2017 年 9 月 21 日
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 2020 年 7 月 27 日
did u get the solution?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by