0

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?

Razvan El
  • 177
  • 3
  • 12

2 Answers2

0

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".

Michael
  • 3,639
  • 14
  • 29
  • I get `sudo: no tty present and no askpass program specified`. BTW where I'm supposed to put the password? – Razvan El Feb 17 '16 at 21:51
  • Yep, it's now working, and you have a completely different problem! I wondered if you were going to get this, but couldn't know that you didn't have sudo configured such that it wouldn't require a password from you. When it does require a password sudo requires a tty so it can interact with the user appropriately to ask for it. – Michael Feb 17 '16 at 21:54
  • You might be able to use the -A of --askpass sudo options (used to acquire password in place of the tty) if they are available on your UNIX's sudo, but this is a whole different issue, and I can't say if this might be appropriate for you. Or, also maybe or maybe not appropriate, you could configure sudo not to require a password for your case. – Michael Feb 17 '16 at 22:05
  • 1
    Have you actually tried googling the new error? http://stackoverflow.com/questions/21659637/how-to-fix-sudo-no-tty-present-and-no-askpass-program-specified-error – Patrick Oscity Feb 17 '16 at 22:20
0

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.

Sasha Fonseca
  • 2,257
  • 23
  • 41
  • 2
    This is ok if you fully appreciate the security issues you're getting into bed with, but I'm just slightly worried that from your phrasing "now all commands that need sudo seem to work" it sounds as though you don't know why this fixes the problem. You're running your entire vm privileged (presumably as root) here, so it's now not requiring a password because there is no privilege escalation to take place, and thus sudo is in even required... – Michael Feb 17 '16 at 22:15
  • @Michael yes I understand that, I was just trying to get further down into the OP's issue and try to provide with some useful information, but thank you for your feedback. – Sasha Fonseca Feb 17 '16 at 22:24