How can I stop MATLAB from returning until after a command-line script completes?

后端 未结 1 1676
野趣味
野趣味 2020-12-08 15:33

I see in the MATLAB help (matlab -h) that I can use the -r flag to specify an m-file to run. I notice when I do this, MATLAB seems to

相关标签:
1条回答
  • 2020-12-08 16:05

    Quick answer:

    matlab -wait -nosplash -nodesktop -r waitHello
    

    In Matlab 7.1 (the version I have) there is an undocumented command line option -wait in matlab.bat. If it doesn't work for your version, you could probably add it in. Here's what I found. The command at the bottom that finally launches matlab is (line 153):

    start "MATLAB" %START_WAIT% "%MATLAB_BIN_DIR%\%MATLAB_ARCH%\matlab" %MATLAB_ARGS%
    

    The relevant syntax of the start command (see "help start" in cmd.exe) in this case is:

    start ["window title"] [/wait] myprogram.exe args ...
    

    A bit higher, among all of the documented command line options, I found (line 60):

    ) else if (%opt%) == (-wait) (
      set START_WAIT=/wait
    ) else (
    

    So specifying -wait should do what you want, as long as you're also exiting matlab from your script (otherwise it will wait for you to terminate it interactively).

    0 讨论(0)
提交回复
热议问题