SUBPROCESS_RUN run process
with optional cwd, env. vars, stdin, timeout
handles command lines with spaces input each segment of the command as an element in a string array this is how python subprocess.run works
Contents
Inputs
- cmd: command line. Windows paths should use filesep '\'
- opt.env: environment variable struct to set
- opt.cwd: working directory to use while running command
- opt.stdin: string to pass to subprocess stdin pipe
- opt.stdout: logical to indicate whether to use pipe for stdout
- opt.stderr: logical to indicate whether to use pipe for stderr
Outputs
- status: 0 is generally success. Other codes as per the program / command run
- msg: combined stdout and stderr from process
Example
subprocess_run('mpiexec -help2'); subprocess_run('sh -c "ls -l"'); subprocess_run('cmd /c "dir /Q /L"');
NOTE: if cwd option used, any paths must be absolute, or they are relative to pwd.
Gfortran streams
https://www.mathworks.com/matlabcentral/answers/91919-why-does-the-output-of-my-fortran-script-not-show-up-in-the-matlab-command-window-when-i-execute-it#answer_101270 Matlab grabs the stdout, stderr, stdin handles of a Gfortran program, even when it's using Java. We must disable this behavior for the duration the running process.