# Jupyter notebook capture stdout and stderr like python capture magic?

**URL:** https://discourse.julialang.org/t/jupyter-notebook-capture-stdout-and-stderr-like-python-capture-magic/26253
**Category:** New to Julia
**Created:** [July 11, 2019, 1:39pm UTC](https://discourse.julialang.org/t/jupyter-notebook-capture-stdout-and-stderr-like-python-capture-magic/26253 "2019-07-11T13:39:59Z")
**Posts on this page:** 1
**Showing post:** 4

<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 11, 2019, 4:20pm UTC](https://discourse.julialang.org/t/jupyter-notebook-capture-stdout-and-stderr-like-python-capture-magic/26253/4 "2019-07-11T16:20:32Z")

</div>

> [@jamblejoe](#):
>
> I do not want to redirect ALL output, just the output of some code running in specific cells in a jupyter notebook.

```julia
let old_stdout = stdout
    rd, = redirect_stdout()
    try
        println("This output is redirected.\n")
    finally
        redirect_stdout(old_stdout) # restore original stdout
    end
    output = String(readavailable(rd))
    println("captured the output: ", output)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/jupyter-notebook-capture-stdout-and-stderr-like-python-capture-magic/26253)._
