Home > Software engineering >  How to launch MATLAB without a desktop in Windows
How to launch MATLAB without a desktop in Windows

Time:10-04

When I run MATLAB like the following from the command prompt or a batch file, I always see a MATLAB command window popping up despite the use of -nodesktop and -nosplash

matlab -wait -nodesktop -nosplash -r "pause(10); quit"

The command window that appears looks like this:

MATLAB Desktop

I am running MATLAB R2021a on Windows 10. According to a somewhat old reference that I found here, -nodesktop has never been not officially supported on Windows (which BTW bothers me! Why would the developers add and test a startup argument, release it, and then say we never support it?). Despite that, I was wondering if anyone has a workaround for how to suppress the MATLAB command window on Windows?

CodePudding user response:

The -nodesktop option was introduced when MATLAB got its Java UI. The option starts MATLAB with the previous interface. I guess they have stopped officially supporting it, but they never removed the option.

MATLAB on Windows has never been quite as comfortable running in a terminal as the Linux and macOS versions—on those OSes, MATLAB does run in the terminal with the -nodesktop option, as they did before the Java UI was introduced.

If you want to run MATLAB non-interactively, use the -batch option. The -r is intended for interactive use, and therefore launches the desktop. The -batch option:

  • Starts without the desktop
  • Does not display the splash screen
  • Executes statement
  • Disables changes to preferences
  • Disables toolbox caching
  • Logs text to stdout and stderr
  • Does not display modal dialog boxes
  • Exits automatically with exit code 0 if statement executes successfully. Otherwise, MATLAB terminates with a non-zero exit code.

(from the docs).

In your case, instead of

matlab -wait -nodesktop -nosplash -r "pause(10); quit"

you should do

matlab -batch "pause(10)"

(I don't know if -wait is still needed on Windows, this is not clear in the documentation, and I don't have Windows to test this.)

  • Related