Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 28 Mär. 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 Kommentare
Jason Ross
Jason Ross am 28 Mär. 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 am 28 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by