# Observe stderr

**URL:** <https://discourse.julialang.org/t/observe-stderr/45533>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 25, 2020, 8:20pm UTC](https://discourse.julialang.org/t/observe-stderr/45533 "2020-08-25T20:20:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 25, 2020, 8:20pm UTC](https://discourse.julialang.org/t/observe-stderr/45533/1 "2020-08-25T20:20:11Z")

</div>

Is there a way to have an observable containing a number (let’s say float) that updates on updates to `stderr`, but where the `stderr` is a string that contains in it the number to be pushed into the observable?

So if I run `run` and it outputs to `stderr`: “and the number is 1.23”  
and i have a function that can extract that number from these strings (using RegEx etc), how do I connect that observable to `stderr`?

Or is there some other more common way of tying a variable to the most recent curated content of `stderr`?

---

<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:** [August 25, 2020, 10:58pm UTC](https://discourse.julialang.org/t/observe-stderr/45533/2 "2020-08-25T22:58:24Z")

</div>

> [@yakir12](#):
>
> Is there a way to have an observable containing a number (let’s say float) that updates on updates to `stderr` , but where the `stderr` is a string that contains in it the number to be pushed into the observable?

What is the context here?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [August 25, 2020, 11:30pm UTC](https://discourse.julialang.org/t/observe-stderr/45533/3 "2020-08-25T23:30:30Z")

</div>

If you can’t modify the code writing to stderr, it’s really unlikely that you can intercept or redirect stderr in-process. If you can modify the code writing to stderr, then find a better way to make it communicate. So if you really must do this, you’ll need another process that’s reading from your stderr, parsing the text, and sending the values back via some IPC such as a socket.

---

<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:** [August 26, 2020, 12:18am UTC](https://discourse.julialang.org/t/observe-stderr/45533/4 "2020-08-26T00:18:01Z")

</div>

> [@Jeff\_Emanuel](#):
>
> If you can’t modify the code writing to stderr, it’s really unlikely that you can intercept or redirect stderr in-process

Sure you can, via `redirect_stderr`. How do you think IJulia redirects stderr (even from external C libraries) to the notebook? You redirect it and then watch the redirected stream in an asynchronous task.

But I agree that it’s something that probably should come up extremely rarely — communicating with code by redirecting and watching `stderr` is kind of a last resort.

PS. Under the hood, `redirect_stderr` works by calling [`dup2`](https://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html), with some additional trickery on Windows.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [August 26, 2020, 12:30am UTC](https://discourse.julialang.org/t/observe-stderr/45533/5 "2020-08-26T00:30:19Z")

</div>

Thanks for the pointer.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 26, 2020, 7:03am UTC](https://discourse.julialang.org/t/observe-stderr/45533/6 "2020-08-26T07:03:44Z")

</div>

> [@stevengj](#):
>
> What is the context here?

Sorry for being so cryptic, here’s the story:  
I want to get the current time stamp from an open session of `ffmpeg`’s `ffplay`. Thanks to efforts from @giordano and @staticfloat we now have `FFplay_jll` available, so we can do this:

```julia-auto
using FFplay_jll
file = "video.mp4"
ffplay() do exe
    run(`$exe $file`)
end

```

and the following line would update with stats about the currently playing frame:

```julia-auto
   3.66 A-V: -0.017 fd= 5 aq= 23KB vq= 554KB sq= 0B f=0/0   

```

where the first float there is the time stamp. I want to capture that number. That’s why I want to listen to `stderr`, and on every change update a value.

## Why don’t you simply use `VideoIO.jl`?

The main reason is that there is an issue with getting the current time stamp when seeking (see issue [Inaccuracies with seek · Issue #242 · JuliaIO/VideoIO.jl · GitHub](https://github.com/JuliaIO/VideoIO.jl/issues/242)). So while building a rudimentary video player with Makie and VideoIO is very possible (see earlier efforts here [GitHub - JuliaIO/VideoPlayer.jl: Video player for Julia](https://github.com/JuliaIO/VideoPlayer.jl)), it is really hard to get accurate time stamps (e.g. with [VFR](https://en.wikipedia.org/wiki/Variable_frame_rate)) after seeking and scrolling in the video.
