Launching MATLAB with no UI (headless) for remote automation
I’m sharing here an answer I just gave at:
for archiving, since this may interest fellow Roboticists
Launching MATLAB on a server without the GUI is covered thoroughly at
you should also read the user comments/discussion there
e.g. you can use
start matlab -nosplash -nodesktop –nojvm –noFigureWindows -minimize -r
The –noFigureWindows parameter is mentioned at
where it doesn’t mention –nodesktop (only the UNIX doc mentions it for X-Windows), however it seems you have to use it on Windows too, else you see the MATLAB code editor window too popup.
I’m not sure the –nojvm works at all on Windows version of MATLAB, it’s not mentioned in the official documentation URL mentioned above and also Process Monitor tool from Microsoft SysInternals shows that MATLAB still loads it’s internal Java VM’s files even with that command-line parameter provided.
If not using Java is too restrictive for your needs:
Regarding -nodesktop vs. -nojvm, there is a third
(undocumented/unsupported) option: ‘-noawt’. -noawt loads Java (thus
enabling Java I/O, data structures etc.) and just prevents Java GUI
Also note that when launching MATLAB from a WCF service, even if you set an AppPool to run the service under a custom account (say MATLABUSER) and even if you set the Matlab current directory / search path for that user (Matlab keeps them separately for each Windows user account), it keeps on ignoring them. Thus you are forced to use “-sd” deprectated command-line parameter of Matlab (mentioned at the official doc URL I sited above) to set the startup path of Matlab. In that folder you can have a “startup.m” file where you use ADDPATH command of Matlab to temprorarily update the Matlab startup path for the running Matlab process.
ADDPATH Add directory to search path.
ADDPATH DIRNAME prepends the specified directory to the current
matlabpath. Surround the DIRNAME in quotes if the name contains a
space. If DIRNAME is a set of multiple directories separated by path
separators, then each of the specified directories will be added.
ADDPATH DIR1 DIR2 DIR3 … prepends all the specified directories to
Unfortunately the “-sd” command-line parameter is deprecated, which means it could be removed in the future, but the Matlab online documentation fails to list alternatives, just says “For information about alternatives, see .” and nothing more there:
BTW, instead of launching MATLAB via Windows shell command you could launch as a COM automation server:
or via existing C API for launching MATLAB:
If you use this often (e.g. from a web service), it is best that you keep an instance of MATLAB in memory all the time (since Windows apps for example share code and have separate data this can spare much time by avoiding the reloading of MATLAB code into memory at every script run). That instance could be headless too (with no UI) using this command at server boot (e.g. by adding an entry at HKLM/Software/Microsoft/Windows/CurrentVersion/Run in the Windows registry using "regedit.exe"):
start matlab -nosplash -nodesktop –nojvm –noFigureWindows -minimize