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.

First Post!

camatcode

camatcode

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

Last Post!

gtcode

gtcode

I made good use of erlexec in claude_code_sdk_elixir:

https://github.com/nshkrdotcom/claude_code_sdk_elixir/blob/9e0d697880b01184abbe5fc2c23a7fa2fb9f2f72/mix.exs#L33

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

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
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

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement