Running Matlab in the linux background using nohup

I have tried different suggested ways that I found in the internet to use nohup for matlab. It does not matter which computing system I use (local mac laptop/remote linux system/remote HPC system) and it does not matter what I write after:
nohup matlab ...
I always receive this error in the output file:
"nohup: matlab: No such file or directory"
while both matlab and nohup are accessible and work for other purposes.

 採用された回答

Walter Roberson
Walter Roberson 2023 年 12 月 11 日

1 投票

I suspect that in your shell, matlab is an alias rather than an executable file on your path.
For example on Mac, you would have to
nohup /Applications/MATLAB_R2023b.app/bin/matlab
unless /Applications/MATLAB_R2023b.app/bin is on your PATH
Note: cron and similar are initialized to have a fairly limited PATH; daemons and executables launched from the dock or by double-clicking do not go through login procedures and so files such as .zshrc are not executed when launching them.

5 件のコメント

Neda
Neda 2023 年 12 月 11 日
Thank you so much Walter. I tried this:
nohup /Applications/MATLAB_R2023a.app/bin/matlab -nodisplay -nosplash -r "run path-to-directory/mycode.m; exit" > file.output 2>&1 &
The previous error did not show up, but I expected a text file to be created after running this code, but nothing came up. It seems matlab code was not executed. file.output is empty.
Walter Roberson
Walter Roberson 2023 年 12 月 11 日
Example:
nohup /Applications/MATLAB_R2023b.app/bin/matlab -nodisplay -nosplash -r "disp(date); exit" > /tmp/file.output 2>&1 < /dev/null &
The redirection of stdin was needed to prevent zsh from suspending the background job when it wanted to do output.
Neda
Neda 2023 年 12 月 11 日
移動済み: Walter Roberson 2023 年 12 月 11 日
Great and thanks a lot! It works well in my local Mac computer!
But I also tried it in a remote Linux system, as it is different from my Mac. The only thing I know about the matlab location is: /usr/local/bin/matlab (there is no application like Mac). However, there is something that hinders running matlab using the command below:
nohup matlab -nodisplay -nosplash -r "run /path-to-directory/mycode.m; exit" > /tmp/file.output 2>&1 < /dev/null &
But nothing came out.
I really appreciate your time.
Walter Roberson
Walter Roberson 2023 年 12 月 11 日
It has been several years since I last installed MATLAB on a Linux system, but that executable name does not look right -- not unless it is a symlink to the actual location.
The discussion at https://www.mathworks.com/matlabcentral/answers/20-how-do-i-make-a-desktop-launcher-for-matlab-in-linux gives several different potential executable names. For example,
nohup /usr/local/MATLAB_R2023a/bin/matlab -nodisplay -nosplash -r "run /path-to-directory/mycode.m; exit" > /tmp/file.output 2>&1 < /dev/null &
You have to look inside the "bin" folder of the MATLAB installation directory in order to find the shell script that starts MATLAB.
Neda
Neda 2024 年 4 月 28 日
Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2023 年 12 月 11 日

コメント済み:

2024 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by