Matlab system stdin pipe

Matlab does not have a native means to pass Matlab data via a stdin pipe to programs called with system. This is not an issue with Python subprocess that is quite robust and featureful. “stdout” and “stderr” are joined by Matlab, available at program completion like:

[ret, msg] = system(...);

where “msg” is the data from stdout and stderr joined together.

The benefits of this method is that is can be faster than using temporary files, and helps avoid filesystem clashes when running many external processes in parallel or asynchronously. This method avoids the need to write additional code directly interfacing memory between Fortran or C and Matlab by using file-based or pipe-based API for data streaming. The penalty for this simplicity is execution speed, but that can be resolved later if I/O speed is a genuine bottleneck by using Matlab Engine or MEX.

Example

As noted by Mathworks staff, Python or Java can be used to pass stdin from Matlab to executable.

These examples can readily be expanded to handle arbitrarily large and complex inputs and outputs via stdin and stdout command line pipes.

Matlab stdin pipe examples (GitHub)

GNU Octave

It is also possible to do this via Java in Octave, but the syntax is slightly different using JavaObject, which is left as an exercise for the reader.