# Using port drivers in OTP

**URL:** <https://erlangforums.com/t/using-port-drivers-in-otp/3143>\
**Category:** Questions / Help\
**Tags:** port\_driver, otp, erlang-otp\
**Created:** [December 24, 2023, 12:03pm UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143 "2023-12-24T12:03:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoeniuxlpr](https://erlangforums.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@phoeniuxlpr](https://erlangforums.com/u/phoeniuxlpr)\
**Post date:** [December 24, 2023, 12:03pm UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143/1 "2023-12-24T12:03:02Z")

</div>

Is there some pattern for using port drivers in OTP?

My plan is running some external programs for some amount of time.

---

<div class="post-metadata">

**Author:** ![vkatsuba](https://erlangforums.com/user_avatar/erlangforums.com/vkatsuba/32/314_2.png) [@vkatsuba](https://erlangforums.com/u/vkatsuba)\
**Post date:** [December 24, 2023, 1:37pm UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143/2 "2023-12-24T13:37:10Z")

</div>

Explore the Erlang documentation’s tutorial on C Ports, an essential feature that facilitates seamless integration between Erlang and C programming languages. The tutorial provides detailed insights and guidance, offering developers a comprehensive resource to understand the intricacies of [C Port](https://www.erlang.org/doc/tutorial/c_port). You also can find useful [Building C/C++ | Rebar3](https://rebar3.org/docs/tutorials/building_c_cpp) documentation useful or at [Erlang.mk User Guide](https://erlang.mk/guide/ports.html) - related to which tool for build project you want to use. Plus, you can take a look to this topic [Erlang Nodes and C Nodes](https://ykasimtemel.medium.com/erlang-nodes-and-c-nodes-e9cc664a99aa).

---

<div class="post-metadata">

**Author:** ![phoeniuxlpr](https://erlangforums.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@phoeniuxlpr](https://erlangforums.com/u/phoeniuxlpr)\
**Post date:** [December 24, 2023, 6:45pm UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143/3 "2023-12-24T18:45:42Z")

</div>

I might haved asked the wrong question. My plan is calling out for ffmpeg via open\_port.

---

<div class="post-metadata">

**Author:** ![max-au](https://erlangforums.com/user_avatar/erlangforums.com/max-au/32/1627_2.png) [@max-au](https://erlangforums.com/u/max-au)\
**Post date:** [January 6, 2024, 10:24pm UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143/4 "2024-01-06T22:24:36Z")

</div>

> [@phoeniuxlpr](#):
>
> My plan is calling out for ffmpeg via open\_port.

There is no specific pattern for it. There is `erlexec` library that implements some convenience, but I have no personal experience with it. If you’re not planning to leverage it, several notes that I accumulated while working on similar externally running code. Most of these notes are clearly visible in OTP `peer` module ([otp/lib/stdlib/src/peer.erl at master · erlang/otp · GitHub](https://github.com/erlang/otp/blob/master/lib/stdlib/src/peer.erl#L307)).

- for every instance of the external executable, have a supervising Erlang process (`peer` implements a `gen_server` for that purpose)
- you may need to use OS level signals (e.g. `kill` on Unix, executed with the same `open_port` approach) to control external executable behaviour)
- be aware of how the executable operates with stdin/stdout (e.g. it may crash if stdin is abruptly closed, or stdout/stderr is not functioning)

---

<div class="post-metadata">

**Author:** ![phoeniuxlpr](https://erlangforums.com/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@phoeniuxlpr](https://erlangforums.com/u/phoeniuxlpr)\
**Post date:** [January 7, 2024, 8:15am UTC](https://erlangforums.com/t/using-port-drivers-in-otp/3143/5 "2024-01-07T08:15:28Z")

</div>

Thanks!
