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/1.py and I want to run it from my Elixir.
Thanks for your help!
SL
NobbZ
August 24, 2017, 9:26am
2
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 "yourscript.py", []
should just work.
If your script is not in path but executable you’ll have to prive absolute path: System.cmd "/tmp/yourscript.py", []
If your script is neither, you need to specify an interpreter: System.cmd "python", ["/tmp/yourscript.py"]
3 Likes
Hey!
Thanks for your reply!
I finally success to run it with the following:
System.cmd “python” [“myscript.py”]
Now i’ll have to figure how to put response.
Thanks again!
NobbZ
August 24, 2017, 10:05am
4
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
Hello!
:ok
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