3

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?

1

1 Answer 1

7

Have you tried adding exit to Matlab command?

/Applications/MATLAB_R2008a/bin/matlab -nodesktop -r "run Documents/MATLAB/BLS/BLS; exit;"
Sign up to request clarification or add additional context in comments.

2 Comments

I did try, but it seems that I did it wrong. I didn't realize I could just use a semicolon there. Feel a bit stupid, actually, it's kind of obvious. Thanks!
@RyanSimmons running matlab in batch requires an exit command at the end to terminate the session. You can put it in the command line (... -r " foo(); exit();") or you can add it to the function/script you are executing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.