Capturing available data written to redirected STDOUT and/or STDERR


I’ve tried to write a set of functions that redirect both STDOUT and/or STDERR (capture_stderr, capture_stdout, capture_console), and return with the data as a string (we use this for testing purposes).

I had originally used readavailable, which seemed to work, except that it blocks if there is nothing available.
Then I tried to modify it to check nb_available, to see if it would block, however, even if readavailable has something to return, it is always returning 0.

Has anybody else run into this problem? (bug maybe?)
I would have thought that nb_availabile would return non-zero, if readavailable had something to return without waiting, but that is not the case.

Issue: Redirect output to an IOBuffer


Basically you put readavailable in a Task so the blocking isn’t an issue:

I have a minimal example here:


Also, for the benefit of future googlers (we already chatted on gitter) - check out Suppressor.jl, which provides nice macros for suppressing and/or capturing stdout and stderr.