# How to get rid of output in nlsolve?

**URL:** <https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559>\
**Category:** Data\
**Created:** [June 25, 2021, 4:02pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559 "2021-06-25T16:02:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 25, 2021, 4:02pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/1 "2021-06-25T16:02:17Z")

</div>

I’m struggling to avoid printing the result after an `nlsolve` call.

```julia
Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [-2.9444389791664403, -2.197224577336219, 2.0, -0.2231435513142097]
 * Zero: [-0.8473798621728809, 4.661998387995021, 2.996397431516435, -2.9186666380101856]
 * Inf-norm of residuals: 0.000000
 * Iterations: 9
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 10
 * Jacobian Calls (df/dx): 9

```

I tried doing this

```julia
redirect_stdout(() -> nlsolve(f!, params_init_vec), devnull)

```

But that doesn’t redirect the summary output. It does, however, make debugging very hard. What `IO` is the summary from `NLSolve` sent to?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 25, 2021, 4:17pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/2 "2021-06-25T16:17:44Z")

</div>

Should just be whatever `IO` is passed to `show`:

> <https://github.com/JuliaNLSolvers/NLsolve.jl/blob/219672802ed79b3d8ae13fdc83febce3bd0acd37/src/nlsolve/solver_state_results.jl#L87-L100>

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 25, 2021, 4:26pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/3 "2021-06-25T16:26:18Z")

</div>

That is obviously true.

But it doesn’t help me understand why `redirect_stdout` doesn’t affect the printing. I also can’t find where the `show` method is actually called in the `nlsolve` function.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 25, 2021, 4:28pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/4 "2021-06-25T16:28:25Z")

</div>

Well - `redirect_stdout` just returns whatever the given function returns, so that’s why it’s probably being printed. The REPL just displays the value it was given, calling `show`:

```julia
julia> redirect_stdout(() -> 1, devnull)
1                                       

```

Would explain why everything _inside_ `nlsolve` is swallowed, but not the summary.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 25, 2021, 4:30pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/5 "2021-06-25T16:30:56Z")

</div>

I apologize. I had a `print` call I hadn’t realized.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 25, 2021, 4:32pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-output-in-nlsolve/63559/6 "2021-06-25T16:32:40Z")

</div>

No need to apologize! We all make these kinds of silly mistakes sometimes 🙂
