sezaru

sezaru

Running a shell command when exiting an Elixir script

I have a mix task that does some stuff, and in the end it created a shell command that I want to run. The command can be something that willl require full IO support, so you can something like a psql session, an ssh session, etc.

Is there some way to run that command before/after exiting the Elixir task/beam so it is executed as a normal command in bash?

If not, is there some way that I can run that command inside the beam, but the beam give full IO handling to the process until it finishes?

Trying to doing something like this with System.cmd doesn’t seem to do the trick.

Most Liked

Hermanverschooten

Hermanverschooten

I used to have an issue with running a system command that needed te be independent of the Beam, I wrote a nif to handle this, don’t know if it will help you. It’s on hex.

I must say it’s been years since I have used it. The project it was for has been archived.

VictorGaiva

VictorGaiva

Why don’t you do the oposite? Call an Elixir Script from a Bash Script, and when it exits you can do anything.

You could even get the exit codes to do some logic.

sezaru

sezaru

Thanks for the suggestion, but it doesn’t seem to work from my tests, it will still not give the keyboard IO control to the external program/shell

gtcode

gtcode

I made good use of erlexec in claude_code_sdk_elixir:

(repo is on an exploratory journey on the main branch currently, apologies)

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
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...
3268 119930 1237
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement