Matlab Gfortran console stream redirect

Matlab redirects the I/O streams of binaries compiled with GFortran by setting runtime environment variables for streams “stdout”, “stderr”, and “stdin”. This can lead to unexpected behavior of programs run from Matlab with built-in functions like system() as well as external language interfaces run from Matlab scripts like Java ProcessBuilder, Python subprocess, etc.

Disable I/O stream capture before the external process is started in the Matlab script:

setenv("GFORTRAN_STDOUT_UNIT", "6");

setenv("GFORTRAN_STDERR_UNIT", "0");

setenv("GFORTRAN_STDIN_UNIT", "5");

Runtime environment variables affect GCC programs including C and C++ programs.