I would like to use Elixir as an admin scripting/programming and using it to run an expect script to logon it to a remote host. The issue being that Elixir does not transfer control to the expect script and hangs. Is there a way to run expect scripts with Elixir without hanging? The Expect is very simple and just logs in a system using ssh.
You’re playing a quite dangerous game by not using “the good language for the good task”.
I would recommend using a language that was designed for such a task
How do you call the external script from Elixir?
If you do not want Elixir to ‘hang’ until the external thing you are calling is finished, you could call it asynchroniously such as within a
Also, there exist libraries such as shell_stream which might make it easier to do.
Finally, there is sshex which might do the SSH-login in Elixir without needing an external script at all.
Qqwy I am using System.cmd to call the script.
I will also take a look at your suggestions.
You have wandered into one of the dusty, poorly documented parts of the BEAM. The mysterious land of Ports… Here be dragons.
There’s a fork in the road. The path you take will depend on whether you just need to get some stuff done or you are playing with Elixir for Elixir’s sake.
If you just need to get some shit done, I would not choose Elixir for this kind of task. Or at least not for the part that directly needs to interact with tty’s and remote processes. It can be done, but it’s different enough and has enough weird edge cases to make the game not worth the candle.
If you are playing with Elixir for Elixir’s sake, then I would start with the Porcelian library.
Ultimately, I think you’ll need to create some kind of daemon in another language that deals with processes and returns results. I could of course be completely wrong about all this and just not persistant enough to figure out how ports actually work.
Appreciate it bbense, I will take a look at porcelain and look more at ports.