Main Content

Redirect Standard Output and Error to Python

This example shows how to redirect standard output and standard error from a MATLAB® function to Python® StringIO objects.

Use the io module to create StringIO objects.

import matlab.engine
eng = matlab.engine.start_matlab()
import io
out = io.StringIO()
err = io.StringIO()
ret = eng.dec2base(2**60,16,stdout=out,stderr=err)

dec2base raises an exception when an input argument is greater than 2^52. Display the error message captured in err.

print(err.getvalue())
Error using dec2base (line 22)
First argument must be an array of integers, 0 <= D <= 2^52.

See Also

|

Related Topics