is there a way to capture stdout in Julia like capture.output() in R?

julia, r

Solution

With Julia 0.2, there is now a way to capture standard output: you can call redirect_stdout to convert `STDOUT` into a pipe that you can read from.

This is mainly useful to capture output from external C libraries. As Stefan mentioned, most Julia I/O functions accept an `io` argument that allows you to print to an arbitrary destination, such as a string buffer.

Problem

In R, `capture.output()` can capture the output to `stdout` in an expression as a character vector, e.g. ``` > x = capture.output(print(1:10)) > x [1] " [1] 1 2 3 4 5 6 7 8 9 10" ``` Is there an equivalent function in Julia?

Original source