简体   繁体   中英

How to pass command line arguments to Mix Release built

I am trying to pass command-line arguments to my elixir release. I have built the release using

MIX_ENV=prod mix release

Now, Am not able to pass any command-line arguments with the start command.

_build/prod/rel/prod/bin/prod start arg1 arg2

Using eval i have achieved passing the arguments but it stops after a while.

_build/prod/rel/prod/bin/prod eval "Hello.nodes([3, :node1])"

Is there any way that I can pass the args through the start flag?

Using eval i have achieved passing the arguments but it stops after a while.

_build/prod/rel/prod/bin/prod eval "Hello.nodes([3, :node1])"

From the docs :

The eval command starts its own instance of the VM but without starting any of the applications in the release and without starting distribution. For example, if you need to do some prep work before running the actual system, like migrating your database, eval can be a good fit. Just keep in mind any application you may use during eval has to be explicitly loaded and/or started.

I'm guessing your eval tires to use an application that you didn't explicitly load before executing the eval.

Is there any way that I can pass the args through the start flag?

It's not documented, but there are various ways to configure a release:

https://elixir-lang.org/getting-started/mix-otp/config-and-releases.html

Maybe an escript would be a better fit?

escript provides support for running short Erlang programs without having to compile them first, and an easy way to retrieve the command-line arguments.

It is possible to bundle escript(s) with an Erlang runtime system to make it self-sufficient and relocatable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM