Ilya
Ilya

Reputation: 1150

Elixir/Phoenix System cmd to start server

I've made a release with Distillery, so I can start it with ./bin/app start, now I'm trying to start it with elixir, like this:

path = "/Users/user/app/0.0.1/bin/"
System.cmd("./app", ["start"], cd: path)

But unfortunately, get :enoent error. I guess it is because ./app is not really a command, but a file. So, my question is, whether it is possible to make it work with System.cmd?

I tried with Enum.join([executable, "start"], " ") |> String.to_char_list |> :os.cmd, but this method won't provide errors, if they happen. So I would prefer to archive same, but with System.cmd.

Any advise appreciated, thank you!

Upvotes: 0

Views: 262

Answers (1)

Dogbert
Dogbert

Reputation: 222060

System.cmd/3 expects an absolute path to the executable if the executable is not in a directory present in PATH:

command is expected to be an executable available in PATH unless an absolute path is given.

Your application's directory is most likely not in PATH, so you can instead pass the absolute path to the app like this:

System.cmd(Path.join(path, "app"), ["start"], cd: path)

Upvotes: 1

Related Questions