axelson

axelson

Scenic Core Team

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.

First Post!

mwgkgk

mwgkgk

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

Most Liked

ConnorRigby

ConnorRigby

Nerves Core Team

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} = :gen_udp.open(0, [{:ifaddr, {:local, '/tmp/testsockin'}}])

and from a shell

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

ConnorRigby

Nerves Core Team

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

Last Post!

lkuty

lkuty

I found that useful to send messages from system cron. Note the use of a backslash in front of %. I have a GenServer called CronServer in charge of parsing the message and calling the appropriate client function in the interested GenServers. I also use sched_ex for cron jobs internal to the app.

5 7 * * * ID=xxx_cron echo "minute. datetime: $(date +'\%FT\%T\%:z')" | socat - UNIX-SENDTO:/tmp/elixir_xxx_cron

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement