How to prevent Matlab from immediately running after using system function to call an .sh script?
조회 수: 6 (최근 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!