필터 지우기
필터 지우기

How to prevent Matlab from immediately running after calling Linux Command?

조회 수: 3 (최근 30일)
unix('a4 -s ~/scripts/a4cmdf_RD_Optim.ses');
%%WAIT until .dat is finished.
get_simdata;
The unix command automatically runs Animator4 with a sessionsfile which in return creates a .dat file.
With get_simdata I read the .dat file.
BUT, the problem is that Matlab already executes the get_simdata before the Animator4 is ready with writing the .dat file. And hence, there is no .dat file yet.
How do I solve this?
Edit: I can use the Pause(3) but that is not a very Elegant option I think.

채택된 답변

Daniel Shub
Daniel Shub 2013년 3월 28일
I believe the unix and system commands do not return until the command you are calling return so that they can get the potential results and exit code to pass back to MATLAB. I would expect that if you do
a4 -s ~/scripts/a4cmdf_RD_Optim.ses
at the Linux command prompt, that it exits immediately. If the Linux command doesn't provide a way to telling you when it is done, there is no easy way for MATLAB to know when it is done.
  댓글 수: 3
Jason Ross
Jason Ross 2013년 3월 28일
You might want to consider adding some logic that will get the file size of the file, then wait, then check the size again. I won't say that I've never used a static pause, but I will say that often times, eventually I end up implementing some sort of polling interval where I started with a pause as the problem grows and starts giving me an incomplete file.
Daniel Shub
Daniel Shub 2013년 3월 28일
If you cannot get an exit status, then I you might want to do something like a ps to look for when the job finishes. This might be easier to script in bash.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by