MATLAB: How to run MATLAB in batch mode on the Mac when I log in remotely so that the process runs when I am logged out

MATLAB

I want to run MATLAB in batch mode on my Mac machine when I log in remotely through SSH. I have tried to use NOHUP, but the process dies as soon as I log off.

Best Answer

In order to start your MATLAB process through the SSH connection and leave it running after you disconnect, you need to use the following commands on the csh/tcsh shell on the Mac:

 unsetenv DISPLAY
 nohup matlab -r mybgprocess -nodisplay -nosplash -nojvm -nodesktop > & ! matlab.out < mystdio.txt &

The file 'mybgprocess.m' contains the MATLAB commands that you want to run. It is important that this function has a QUIT or EXIT statement at the end so that the MATLAB process is closed after you script is done executing. The file 'mystdio.txt' can be an empty file, but it needs to exist. Without this file, the standard input of the MATLAB process would be empty, which would cause the MATLAB process to die. The file 'matlab.out' will store the output of the MATLAB Command Window to your commands.