How to execute external scripts of python/bash/ruby from elixir?

Hi all,
I’m facing with a problem that I didn’t find while searching in Google.
I need to execute python scripts from elixir, so I tried System.cmd/3 and it didn’t work.
Any way to do so on elixir?
E.g. I have file on /tmp/ and I want to run it from my Elixir.

Thanks for your help!

What exactly have you tried when using System.cmd/3? And what error did you get?

Possible solutions, based on the most common mistakes made with System.cmd/3:

  • If your script is executable and in path System.cmd "", [] should just work.
  • If your script is not in path but executable you’ll have to prive absolute path: System.cmd "/tmp/", []
  • If your script is neither, you need to specify an interpreter: System.cmd "python", ["/tmp/"]

Thanks for your reply!
I finally success to run it with the following:

System.cmd “python” [“”]
Now i’ll have to figure how to put response.

Thanks again!

What do you mean by “put response”?

Do you mean this:

iex(1)> {out, _} = System.cmd "python", ["-c", ~s(print "Hello!")]
{"Hello!\n", 0}
iex(2)> IO.puts out


put == get.
Yea that’s what I did too.
Thanks again!

You may what to have a look at The Erlangist - Outside Elixir.

1 Like