How to run a cmd command with System.cmd/3?

Hi,

I’m trying to run a script using System.cmd/3 but I’m getting an :enoent error.

Here’s the error output:

    [error] Task #PID<0.427.0> started from #PID<0.373.0> terminating
** (stop) :enoent
    (elixir) lib/system.ex:632: System.cmd("echo", ["hello"], [])
    (ex_test) lib/ex_test_web/commanders/page_commander.ex:19: anonymous fn/2 in ExTestWeb.PageCommander.run_async_tasks/2
    (elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:38: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: #Function<2.128760482/0 in ExTestWeb.PageCommander.run_async_tasks/2>
    Args: []
[error] Drab Process #PID<0.373.0> died because of :enoent
    (elixir) lib/system.ex:632: System.cmd("echo", ["hello"], [])
    (ex_test) lib/ex_test_web/commanders/page_commander.ex:19: anonymous fn/2 in ExTestWeb.PageCommander.run_async_tasks/2
    (elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:38: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Any ideas whats wrong?

You probably do not have echo in PATH.

Please check on a terminal if which -a echo gives you at least one result that is not a function or built-in.

Then check if the prefix of that output is available in the PATH visible to your application (System.get_env("PATH")).

1 Like

I think I don’t, but it works in the cmd when I type it in manually.

I got: 'which' is not recognized as an internal or external command, operable program or batch file.

I tried System.get_env() in iex, it outputted a list that did not include echo.

Update:

I’m on win10 and System.cmd() gives me the same error regardless of what I put into the first argument.

So you are on windows? There is no echo executable then, with a bit of luck System.cmd("cmd", ["echo", "foo"]) might work, but no guarantees for nothing…

2 Likes

I found this just before you posted this reply.

Basically it’s the same thing and it works :slight_smile:

1 Like