# Capturing available data written to redirected STDOUT and/or STDERR

**URL:** https://discourse.julialang.org/t/capturing-available-data-written-to-redirected-stdout-and-or-stderr/6378
**Category:** General Usage
**Created:** [October 10, 2017, 1:07pm UTC](https://discourse.julialang.org/t/capturing-available-data-written-to-redirected-stdout-and-or-stderr/6378 "2017-10-10T13:07:50Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [August 21, 2022, 7:26pm UTC](https://discourse.julialang.org/t/capturing-available-data-written-to-redirected-stdout-and-or-stderr/6378/5 "2022-08-21T19:26:51Z")

</div>

**2022 update!**

Now there’s [`Base.redirect_stdio`](https://docs.julialang.org/en/v1/base/io-network/#Base.redirect_stdio), which, according to the name, should be able to redirect the input/output streams to… other streams, I guess. Since [`IOBuffer`](https://docs.julialang.org/en/v1/base/io-network/#Base.IOBuffer) is “an in-memory I/O stream” (so basically an [`IOStream`](https://docs.julialang.org/en/v1/base/io-network/#Base.IOStream), but in-memory), I assumed it was possible to redirect output to an `IOBuffer`:

```julia
buf_stdout, buf_stderr = IOBuffer(), IOBuffer()
redirect_stdio(stdout=buf_stdout, stderr=buf_stderr, stdin=devnull) do
    @info "Hello!"
end

```

However, this doesn’t work:

```julia
MethodError: no method matching (::Base.RedirectStdStream)(::IOBuffer)
  Closest candidates are:
    (::Base.RedirectStdStream)() at stream.jl:1254
    (::Base.RedirectStdStream)(::Union{IOStream, Base.LibuvStream}) at stream.jl:1222
    (::Base.RedirectStdStream)(::Function, ::Any) at stream.jl:1417
    ...
  Stacktrace:
    [1] redirect_stdio(; stdin::Base.DevNull, stderr::IOBuffer, stdout::IOBuffer)
      @ Base ./stream.jl:1315
    [2] redirect_stdio(f::var"#9#11"{Symbol, Symbol, Matrix{Float64}}; stdin::Base.DevNull, stderr::IOBuffer, stdout::IOBuffer)
      @ Base ./stream.jl:1405
    ...

```

So apparently, `IOBuffer`, being “an in-memory I/O stream”, is actually _not_ a proper `IOStream`, since it’s not possible to `redirect_stdio` to it.

There’s an [issue](https://github.com/JuliaLang/julia/issues/12711) about this, but it’s been open since 2015, and it doesn’t look like there’s a generally accepted solution…

---

_[View the full topic](https://discourse.julialang.org/t/capturing-available-data-written-to-redirected-stdout-and-or-stderr/6378)._
