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.
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.
This will create an ssh session to a server I have in Fly and halt the beam. Since the process is outside the beam, it does keep running, but then it will give me the following error because it can’t access the input/output:
Connecting to fdaa:20:...:f93c:2... complete
Error: ssh shell: input/output error
I don’t remember the code it is too long ago I wrote it.
But what comes to mind is if you could pass along the current file descriptors for input and output to the new process or could be you need to start a pty.