# How to redirect IO to a string?

**URL:** <https://discourse.julialang.org/t/how-to-redirect-io-to-a-string/64661>\
**Category:** New to Julia\
**Created:** [July 14, 2021, 9:45pm UTC](https://discourse.julialang.org/t/how-to-redirect-io-to-a-string/64661 "2021-07-14T21:45:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [July 14, 2021, 9:45pm UTC](https://discourse.julialang.org/t/how-to-redirect-io-to-a-string/64661/1 "2021-07-14T21:45:16Z")

</div>

For example, the built-in `versioninfo()` function accepts arguments

```
versioninfo(io::IO=stdout; verbose::Bool=false)

```

The return result of this function is `nothing`. How can I get the output not as IO printing but as a string? Can I create an object of type `IO` but secretly stores the result into a string?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 14, 2021, 9:48pm UTC](https://discourse.julialang.org/t/how-to-redirect-io-to-a-string/64661/2 "2021-07-14T21:48:16Z")

</div>

Use an `IOBuffer`:

```julia
buf = IOBuffer()
versioninfo(buf)
String(take!(buf))

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [July 14, 2021, 9:54pm UTC](https://discourse.julialang.org/t/how-to-redirect-io-to-a-string/64661/3 "2021-07-14T21:54:21Z")

</div>

See also `sprint`.
