Matlab system() environment variables
Matlab system() discards the shell environment variables. Set environment variables in name-value pairs like:
if ispc
system("echo %test_var%", test_var="hello")
else
system("echo $test_var", test_var="hello")
end
Multiple environment variables can be set in a single command by adding more name-value pairs.
To set specific environment variables desired to set in the system command, do like this example for “CC”:
system("make", CC=getenv("CC"))
To set multiple environment variables:
env = namedargs2cell(struct(CC="gcc", CXX="g++"));
system("make", env{:});
For more advanced Python-like subprocess control from Matlab, use matlab-stdlib subprocess_run() that allows setting environment variables, cwd, stdin pipe, timeout, and more.