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

5 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Jan 2010

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.

More Answers (1)

Leon
Leon on 29 Aug 2018
The command seems to be truncated. Anyone has the full command?
Thanks!
  2 Comments
Walter Roberson
Walter Roberson on 29 Aug 2018

The command is not truncated, but it does depend upon an alias having been created pointing matlab to the correct location, or at least that /Applications/MATLAB_R20XXx.app/bin/ being on the path.

The command given is for csh / tcsh, which is an odd thing to have given as it is not the default for Mac. The default or Mac is bash. The bash equivalent would be

 nohup matlab -r mybgprocess -nodisplay -nosplash -nojvm -nodesktop > matlab.out 2>&1 < mystdio.txt &

Here, matlab.out indicates the name of the file where all of the output is to be sent, and mystdio.txt indicates the name of the file from which all input() statements are to take their input (might affect what happens for keyboard() as well.)

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2007b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!