How can I send a process a message from a shell script?

Is there a straightforward way to send a message to my Elixir process from a bash script?

To avoid the XY problem, I am trying to implement a pianobar eventcmd, which is a script that is run on each event (such as song change) and receives the majority of it’s input via stdin. Should I use a pipe? I could do an HTTP Request but that seems awfully inefficient.

1 Like

Would love to know as well! D-Bus and Websockets come to mind.

I can think of solving this a number of ways. Do you have distribution available? If not i would use a domain socket if you are on a Linux or OSx machine. (i think OSX supports unix domain sockets)
From an iex session:

{:ok, sock} =, [{:ifaddr, {:local, '/tmp/testsockin'}}])

and from a shell

echo 'Hello, World!' | socat - UNIX-SENDTO:/tmp/testsockin

I’m thinking of trying to solve this without distribution since I don’t want to trust the network. That said these two processes will be on the same machine (although there will be another machine running Nerves and Scenic, but that will be a different communication mechanism). The machine running pianobar will be Linux (although it would be nice to support OS X as well).

What advantages does a domain socket have over a named pipe if we want to operate within the same operating system?

I know how to setup a domain socket and not a named pipe in Elixir :slight_smile:

1 Like

Just in case, you can use something like config :kernel, inet_dist_use_interface: {127, 0, 0, 1} to bind only on localhost (loopback).

1 Like

Well, that was unexpectedly tediuous …