Unix commands in Matlab

1 view (last 30 days)
Jim O'Doherty
Jim O'Doherty on 2 Apr 2015
Commented: Derek on 14 Oct 2016
Hi,
I've installed a series of binaries which appear in usr/local/bin on my MACOSX (They're called DCMTK). The usr/local/bin folder appears on the path as expected:
/Users/jim/Library/Enthought/Canopy_64bit/User/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:niftyreg_install/bin
I can run these commands as expected from any folder in a Terminal window, however I can't seem to run any of them from within Matlab (2014b) using the command:
cmd=['dcmdump -h'];
system(cmd)
/bin/bash: dcmdump: command not found
Running 'env' in a Terminal shows that I am using the same SHELL as Matlab:
SHELL=/bin/bash
My question is why is it when Matlab invokes bin/bash it is not finding the binaries in usr/local/bin? Is there something I need to update?
Thanks,
Jim

Answers (1)

Jim O'Doherty
Jim O'Doherty on 2 Apr 2015
Edited: Jim O'Doherty on 2 Apr 2015
I've managed to get some help elsewhere on this issue, thought I'd post here in case anyone else has the same problem.
Echo the PATH from MATLAB itself:
cmd=['echo $PATH']; system(cmd);
In my case this gave:
/usr/bin:/bin:/usr/sbin:/sbin
and does not include the usr/local/bin where my binaries are stored. Therefor this needs to be added via
setenv('PATH', [getenv('PATH'),':','/usr/local/bin']);
which now gives:
cmd=['echo $PATH']; system(cmd);
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
If you start Matlab from a terminal the PATH is different, and contains usr/local/bin, but starting it the "usual" way through Applications causes a different PATH. No idea why!
Jim
  1 Comment
Derek
Derek on 14 Oct 2016
Thanks Jim. I've run into exactly the same problem. It would be great if Matlab run from the icon would grab all of the environmental variables.

Sign in to comment.

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!