I've got a OpenCL program with some printf() function and this program run over pyOpenCL. I want to store the stdout in a variable. My actual code to try achieve this is:
from io import StringIO # Python3 use: from io import StringIO
import sys
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
# fpga_conv = conv2d.Matmul(H, fpga_mtx, s_mask_ref.astype(np.int32), 1, 0)
# Call to the OpenCL program via pyOpenCL
fpga_ref = conv2d.Matmul(H_ans, fpga_mtx, s_mask_ans.astype(np.int32), 1, 1, (H_h, H_w))
sys.stdout = old_stdout
string = mystdout.getvalue() # Store stdout in a var
But only catchs the python print() stdout. It's possible get all the stdout? The only way that I've found is running the script in bash with the instruction python module.py &> "ref.txt"
that stores the printf() stdout in ref.txt file. I need to run the program via IDE (Spyder in this case), not in the bash terminal.
Any sugesstion or trick? Thx!