如何在命令行脚本完成之后停止返回MATLAB? [英] How can I stop MATLAB from returning until after a command-line script completes?
问题描述
我在MATLAB帮助( matlab -h
)中看到,我可以使用 -r
m
- 要运行的文件。我注意到当我这样做,MATLAB似乎启动脚本,但立即返回。脚本处理正常,但主应用程序已经返回。
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 start the script, but immediately return. The script processes fine, but the main app has already returned.
有什么办法让MATLAB只在命令完成后返回?如果你从一个单独的程序调用它,似乎比等待使用一个文件或套接字来确认完成更容易等待。
Is there any way to get MATLAB to only return once the command is finished? If you're calling it from a separate program it seems like it's easier to wait on the process than to use a file or sockets to confirm completion.
为了说明,这里示例函数 waitHello.m
:
To illustrate, here's a sample function waitHello.m
:
function waitHello
disp('Waiting...');
pause(3); %pauses 3 seconds
disp('Hello World');
quit;
我试着运行:
matlab -nosplash -nodesktop -r waitHello
推荐答案
快速回答:
matlab -wait -nosplash -nodesktop -r waitHello
在Matlab 7.1(版本我有)在matlab.bat有一个未记录的命令行选项-wait。如果它不适合你的版本,你可以添加它。这是我发现的。最后启动matlab的命令是(行153):
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%
start命令的相关语法help start在cmd.exe中)在这种情况下是:
The relevant syntax of the start command (see "help start" in cmd.exe) in this case is:
start ["window title"] [/wait] myprogram.exe args ...
在所有记录的命令行选项中, (line 60):
A bit higher, among all of the documented command line options, I found (line 60):
) else if (%opt%) == (-wait) (
set START_WAIT=/wait
) else (
所以指定-wait应该做什么,只要你也从你的脚本退出matlab(否则它会等待你以交互方式终止)。
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).
这篇关于如何在命令行脚本完成之后停止返回MATLAB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!