fmn

fmn

Hello there!

I am exploring ways of running external programs via Elixir, and to my surprise I didn’t found a way to read from called program’s stdout and stderr separately.

It seems that this is related to how Erlang primitives are handling that task.
Only thing I found, is open_port/2’s stderr_to_stdout option, to merge both streams, and it seems Elixir’s Port.open does the same.

I found some external modules for Erlang supposedly addressing my need, but my question would be: is there elegant / native way to do it in Elixir?

Alternatively, is there a way to call bare sysalls on POSIX platform?

P.S. I wasn’t really sure where to post that question or how exactly label / tag it - my apologies if something went wrong here!

Kind regards,
F.

Showing Posts 1 to 10

peerreynders

peerreynders

Welcome to the forum!

Have you had a look at this yet (if you were thinking about pipes)?

fmn

fmn OP

Hi @peerreynders, thank you for the response!

With my current knowledge of Elixir I guess that I can try to achieve what I want with - for example - 2 named pipes or named pipe plus stderr or stdout? All the moving parts around it seem to me bit intimidating.

Following links mentioned in the thread you’ve shared, I found also how do I communicate with non-Erlang programs, I guess I will go through it, but it will take time :slight_smile:

Thanks again!
F.

peerreynders

peerreynders

While back from 2015 this may still be of some help:

The Erlangelist: Outside Elixir: running external programs with ports

by Saša Jurić, author of Elixir in Action 2e.

OvermindDL1

OvermindDL1

For note, Port’s are more for running with programs designed to work with your BEAM program, it’s less for running ‘other’ things as it doesn’t have this control over file descriptors, PID handling, or anything. If you want to manage programs that aren’t designed to be Port programs then I recommend using something like erlexec or so as it uses a shim C program to act as the binding layer between a Port call and Everything else.

fmn

fmn OP

Thank you for the reply, much appreciated @OvermindDL1.
Yes, that’s the module I’ve found, but I was searching something more lightweight, native, so to speak, but after your post I think I understand situation better.

As a side-note - it feels quite exotic to me, I’ve never encountered such design during my adventures with other programming languages; it’s interesting.

Cheers,
F.

OvermindDL1

OvermindDL1

Yeah that is the native way here. ^.^

The only way to do mutability on the BEAM (short of some hacks) is via message passing, and Ports are just “Message Passing” back and forth to an external process designed for it, so it fulfills that model.

Multiple paths of streams doesn’t. So a hoisting program or NIF or something can fill that void by wrapping a higher level layer into the message passing structure. Which is what erlexec does. :slight_smile:

Yeah the BEAM is not so much a VM like Java, it’s designed to pretend to be it’s own standalone operating system internally within it. ^.^

tme_317

tme_317

You can also look at porcelain with or without goon plugin which despite its age still works well for me when I needed stdin control beyond what System.cmd can provide without digging into low-level Ports.

That said erlexec is better maintained and I found (but not tried) a more idiomatic Elixir wrapper for it exexec

NobbZ

NobbZ

There is also rambo which might come in handy as an alternative to porcelain and goon, as it’s wrapper does not use go and it’s runtime…

fmn

fmn OP

Thank you for all of the suggestions folks!

DiodonHystrix

DiodonHystrix

I had a similar problem, what I did was to pipe stderr to a temp file. A bit ugly, but it worked from what I remember :stuck_out_tongue:

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

HR_Sportograf
Backend Developer for Elixir (F/M/D) - Shape the Future of Sports Photography with Us!(German Version below) About us We are athletes –...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews