问题
My peers have created an extremely-hard-to-test novel structure where they use stdout for outputting results. Now I cannot change their code and I need to use their functions. Suppose a function mlfpprint
that uses stdout for displaying results -- now I need to check whether its results are correct so I need to get the stdout to a variable for comparison with the correct result. So
How can I manage file-descriptors in Matlab? For example, how can I get stdout to stdin?
回答1:
One idea would be to use diary to save the output of your function call/script to a file. Then parse the file. Also as Oleg recommended, you can use evalc like evalc('functionName')
.
来源:https://stackoverflow.com/questions/15990891/how-to-redirect-stdout-to-stdin-in-matlab-aka-how-to-manage-file-descriptors