devie
devie

Reputation: 332

Using System.cmd/3 in Elixir

Probably a naive questions,

I've got this in ruby

system(ansible-playbook -i #{ip_address}, #{file_to_run}")
system(sudo chmod -R ugo+rw /etc/ansible)

Trying to reproduce this with variances of System.cmd/3

System.cmd("sudo chmod -R ugo+rw /etc/ansible",[],[])

Getting an

 (ErlangError) erlang error: :enoent

Please how do i correct this?

Upvotes: 1

Views: 581

Answers (1)

Dogbert
Dogbert

Reputation: 222158

Each argument to the command must be given as a separate string in the list passed as second argument to System.cmd/3:

System.cmd("sudo", ["chmod", "-R", "ugo+rw", "/etc/ansible"])

If all the arguments are literal strings and none of them contain a space you can also use the ~w sigil:

System.cmd("sudo", ~w(chmod -R ugo+rw /etc/ansible))

Since System.cmd/3 has a default value for the third argument, you can omit that like I've done above.

Upvotes: 5

Related Questions