1

I’m finding that if I do the following everything works as expected:

$ iex --sname console --remsh eprocess@service
eprocess@service)1> MyModule.process()

However, MyModule is not available if I try:

$ iex --sname console --remsh eprocess@$HOSTNAME -e "MyModule.process()"

The error is:

** (UndefinedFunctionError) function MyModule.process/0 is undefined (module MyModule is not available)

Does anyone know how to include dependencies from mix when using the -e flag?

Olshansky
  • 5,904
  • 8
  • 32
  • 47
  • You could try adding the alias into the expression to evaluate--like so: `-e "(alias MyModule; MyModule.process())"` NB due to the way that multiple expressions are evaluated, you need to add parentheses around the expression. – Onorio Catenacci Mar 21 '18 at 17:03
  • No luck. Same error persists. – Olshansky Mar 21 '18 at 18:18
  • The `-S` parameter specifies a script to run. You should be able to create a script--for example `runmyprocess.exs` and then add `-S runmyprocess` to the end of your commandline. – Onorio Catenacci Mar 21 '18 at 20:52
  • Same issue. I don't think my my application specific modules are loaded into iex when the "-e" or "-S" params are evaluated. – Olshansky Mar 23 '18 at 19:00
  • @OnorioCatenacci I managed to overcome the import issue by writing a script that adds `-pa */ebin` for every dependency I have. However, the call I want to make is DB dependent so it's saying that the repo is not started. I manually call Mix.Ecto.ensure_started(Repo), but now it says that the configs are not specified. I'm really not sure what to do... – Olshansky Mar 23 '18 at 21:44
  • In fact, here's something interesting: `iex --sname console --remsh eprocess@$HOSTNAME -e "IO.inspect(Application.get_env(:a, :b))"` -> result: nil `iex --sname console --remsh eprocess@$HOSTNAME` `iex> IO.inspect(Application.get_env(:a, :b)` -> result: not nil Seems like the command we pass to "-e" doesn't have access to the application's context, but the shell that gets started up afterwards does. – Olshansky Mar 23 '18 at 21:52

0 Answers0