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

4 views (last 30 days)
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.

Accepted Answer

Daniel Shub
Daniel Shub on 28 Mar 2013
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 Comments
Jason Ross
Jason Ross on 28 Mar 2013
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 on 28 Mar 2013
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!