# How to continuously communicate with an external program?

**URL:** https://discourse.julialang.org/t/how-to-continuously-communicate-with-an-external-program/86319
**Category:** General Usage
**Tags:** question
**Created:** [August 25, 2022, 12:10pm UTC](https://discourse.julialang.org/t/how-to-continuously-communicate-with-an-external-program/86319 "2022-08-25T12:10:09Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ArthurW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arthurw/32/19561_2.png) [@ArthurW](https://discourse.julialang.org/u/ArthurW)
#### Post date: [August 25, 2022, 9:59pm UTC](https://discourse.julialang.org/t/how-to-continuously-communicate-with-an-external-program/86319/5 "2022-08-25T21:59:57Z")

</div>

It’s the buffering of the external program’s output!  
Since Julia doesn’t call the external program via a terminal, it’s output is _block-buffered_: it will only be writen to _stdout_ once there is enough data to be worth the trouble.

In the end, it’s sufficient to get the IO of the external program to be _line-buffered_ (or not buffered at all, but it would be less eficient). That is, to have the output of the program to be effectively written to it’s out-stream (`proc.out`) after every line break (`\n`). There are multiple ways to instruct the system to do this. I’ve achieved it via the `stdbuf` command:

```nohighlight
julia> proc = open(`stdbuf -oL ./exec`, write=true, read=true)
Process(`stdbuf -oL ./exec`, ProcessRunning)

julia> println(proc, "12")

julia> readline(proc)
"13"

julia> println(proc, 23)

julia> readline(proc)
"24"

```

(Notice that all of this means that adding an `fflush(stdout)` to the C code in the question would fix the issue. But, in pratice, this wasn’t an option for me since cannot modify the external program.)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-continuously-communicate-with-an-external-program/86319)._
