0
votes

I would like to make system calls from Elixir/Erlang. I know Erlang has the OS module and Elixir has the System module but I can't figure out from those links how should I use sudo. I tried running this and I received an error:

> System.cmd("sudo su", [])
** (ErlangError) erlang error: :enoent
(elixir) lib/system.ex:450: System.cmd("sudo su", [], [])

Any ideas on how can I make this work?

2

2 Answers

0
votes

ENOENT is POSIX speak for "no such file or directory". It's looking for the "sudo su" command and not finding it.

Try System.cmd("sudo", ["su"], []) instead, which will invoke the "sudo" command with a single argument "su".

0
votes

I can't seem to use sudo inside a System.cmd. It gives the following error:

sudo: no tty present and no askpass program specified

which I guess means that a certain program related to typing password must be present. However, what I managed to do was to use sudo when calling iex -> sudo iex and now all commands that need sudo seem to work.

The Erlang docs don't seem to specify anything about this either.