Force Matlab to continue when stuck in busy mode?
43 次查看(过去 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 个评论
回答(1 个)
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
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?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!