Force Matlab to continue when stuck in busy mode?

37 次查看(过去 30 天)
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
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by