I am running R2106b on a Macbook Pro OS X Yosemite.
In a Terminal window (using bash shell), if I type
which which
I get the expected output
/usr/bin/which
and similarly
which psql
yields
/usr/local/bin/psql
All is well and good so far. But if I issue these same command from within MATLAB, using the system() command, I get output that perplexes me. As expected, when I type
[status cmdout] = system('which which')
I get
status = 0cmdout = '/usr/bin/which '
But from
[status cmdout] = system('which psql')
I get
status = 1cmdout = 0×0 empty char array
Finally, if I point directly to the known directory (which in my real application I would not know) …
[status cmdout] = system('which /usr/local/bin/psql')
then the command is found
status = 0cmdout = '/usr/local/bin/psql '
Does anyone have some insight into what is happening here? I am not a Unix expert by any means. But the whole thing seems to be a bit of a shell game. 😉
(I can add the why I am doing this if needed, but I won't burden folks just yet.)
Best Answer