1
votes

I have a bash script that I want to execute from within MATLAB. I use system() to execute it. However when it executes I get

docker: command not found

I am using docker commands from within the script and I have it properly installed in my computer. If I run the script from the terminal using the exact same command I have running from the system() call in MATLAB it works fine. To the extent that if I just remove the bash script execution call from my MATLAB function (the last line) and run the function and then run the script from the terminal it all works.

For example here is a MATLAB function:

function foo(container_id)
% Copies this file to the root of a docker container given by container_id
system(['./copy_foo.sh ' container_id])
end

And here is the bash script

#!/bin/bash

docker cp foo.m $1:/root

Running it from the terminal

./copy_foo.sh CONTAINER_ID

produces the desired result. Running the Matlab function from the command window

foo('CONTAINER_ID')

yields:

docker: command not found
1
Could you share a minimal reproduction example for the script in question? - Paolo
And also show how you are using the system command - Paolo
The shell run by system might use a different PATH, see "UNIX tips and limitations" here - Benjamin W.
I edited the question with what you asked. How could I set the path to make this work? - HashBr0wn
the docker executable does not seem to be within your $PATH in the subshell that Matlab opens when you use their system() call. What if you explicitly set the same PATH (that you have in your bash terminal) in your bash script? - lab9

1 Answers

0
votes

MATLAB changes the environment variables when starting up. In particular, LD_LIBRARY_PATH and PATH are affected. There are two solutions:

  1. Use explicit path to the docker executable. Your Bash script would contain the line /path/to/docker cp foo.m $1:/root.

  2. Ensure the environment is initialized properly before running your script. Your MATLAB script would contain the line system(['bash --login -c ./copy_foo.sh ' container_id]) (or something similar, I haven't tested this...).