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

1 次查看(过去 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