How to prevent Matlab from immediately running after using system function to call an .sh script?
5 ビュー (過去 30 日間)
古いコメントを表示
I'm running a Matlab script on windows 10, which in turns calls a shell script file in order to run some simulations on Ubuntu using bash. By definition the Matlab "system" function waits for the .sh file to finish before continuing the executation of the Matlab script. The problem arises when the .sh function calls a subprocess, because in that case Matlab doesn't wait for this subprocess to finish and continues the execution of the Matlab script. Does somebody knows how to force Matlab to wait for the total completion of the .sh script before continuing execution?
0 件のコメント
回答 (1 件)
Precise Simulation
2020 年 3 月 5 日
Not perfect but for the FEATool Multiphysics toolbox a lot of exernal system calls are used, for example for grid and mesh generation and solvers such as OpenFOAM, and for this temporary "lock" files work quite well.
In this case the Matlab code would call the system call with the & postfix as "system( 'my_script.sh &' )" after which a while loop checks for the existance of a "lock" file and exits the loop when not found. The shell script would first write an empty file like "C:\temp\lock" and then delete it after the last script action. It is not perfect and locks up the Matlab thread, but can be made quite robust and handle error cases.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!