# Redirect stdout, stderr to string/stream C++ (embedded)

**URL:** <https://discourse.julialang.org/t/redirect-stdout-stderr-to-string-stream-c-embedded/124210>\
**Category:** New to Julia\
**Tags:** embedding\
**Created:** [December 27, 2024, 3:02pm UTC](https://discourse.julialang.org/t/redirect-stdout-stderr-to-string-stream-c-embedded/124210 "2024-12-27T15:02:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [December 27, 2024, 3:48pm UTC](https://discourse.julialang.org/t/redirect-stdout-stderr-to-string-stream-c-embedded/124210/2 "2024-12-27T15:48:08Z")

</div>

> [@Nelson-numerical-sof](#):
>
> But if I do:
> 
> ```julia
> jl_eval_string("1+1");
> 
> ```
> 
> result of stdout is not in available

What would you expect in `stdout` from evaluating `1+1`? It doesn’t print anything.

(When you enter an expression at the interactive `julia>` REPL prompt, it calls `display` on the result of the expression, which outputs it to `stdout`. But this isn’t done for expressions evaluated with `jl_eval_string`.)

Note that a more robust way to redirect `stdout` to a `String` is to use `redirect_stdout`, see e.g. [Jupyter notebook capture stdout and stderr like python capture magic? - #4 by stevengj](https://discourse.julialang.org/t/jupyter-notebook-capture-stdout-and-stderr-like-python-capture-magic/26253/4)

PS. I fixed the formatting in your post, but for the future please read: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

_[View the full topic](https://discourse.julialang.org/t/redirect-stdout-stderr-to-string-stream-c-embedded/124210)._
