Ryan Simmons
Ryan Simmons

Reputation: 883

Running MATLAB from Unix shell script

I am having some trouble running a MATLAB script from a Unix shell script on my Mac OS (Mountain Lion).

I know how to call the MATLAB script from the shell, and that works fine. However, the problem is that I want my shell script to then call another program after MATLAB finishes running. But when the MATLAB program finishes, the shell is "stuck." That is, it doesn't continue executing the other functions in the shell, and the Terminal window is stuck in the MATLAB environment instead of returning control to sh.

What do I do here? Here is a copy of my shell:

#! /bin/sh
echo "Please make sure the network cable is plugged in" 
echo "(then press return to continue)"

sudo mv /System/Library/CoreServices/Dock.app /System/Library/CoreServices/Dock.app.bak
killall Dock

/Applications/MATLAB_R2008a/bin/matlab -nodesktop -r "run Documents/MATLAB/BLS/BLS"

sudo mv /System/Library/CoreServices/Dock.app.bak /System/Library/CoreServices/Dock.app

# OTHER COMMANDS AFTER HERE CALLING OTHER PROGRAMS ...

The two "sudo mv" commands are just making the Dock invisible during the execution of MATLAB, and bringing it back after MATLAB finishes.

The first command works perfectly, and makes the Dock invisible, then runs MATLAB. However, when MATLAB finishes running, it doesn't continue with the rest of the shell. The terminal is "stuck" in MATLAB. I have tried fiddling around with named pipes and such, but I couldn't get any of them to work.

How do I get it to continue executing the shell script after MATLAB is finished?

Upvotes: 3

Views: 5902

Answers (1)

Shai
Shai

Reputation: 114936

Have you tried adding exit to Matlab command?

/Applications/MATLAB_R2008a/bin/matlab -nodesktop -r "run Documents/MATLAB/BLS/BLS; exit;"

Upvotes: 7

Related Questions