MATLAB Answers

0

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?

Asked by MathWorks Support Team on 21 Jan 2010
Latest activity Commented on by Leon
on 29 Aug 2018
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.

Tags

No tags entered yet.

Products


Release

R2007b

3 Answers

Answer by MathWorks Support Team on 21 Jan 2010
 Accepted 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.

  0 Comments

Sign in to comment.


Answer by shuai hua on 1 Aug 2018

It helps.
Thanks,
Shuai Hua

  0 Comments

Sign in to comment.


Answer by Leon
on 29 Aug 2018

The command seems to be truncated. Anyone has the full command?
Thanks!

  2 Comments

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.