I'm sure this will be so simple I will kick myself my asking but how do I pass erl args, like -config {file} to erl when calling rebar shell? I thought it would simply passthrough anything that didn't match it's own switches but not so.
rebar shell doesn't appear to allow arguments, but it's basically the equivalent of the following command line:
erl -pa deps/*/ebin -pa ebin
If your project has no dependencies, you don't need the -pa deps/*/ebin part.
If you need extra arguments, just add them to this command.
Another alternative is to use the ERL_FLAGS environment variable to specify extra arguments:
ERL_FLAGS='-config my_config_file.config' rebar shell
rebar3 supports this directly now:
rebar3 shell --config something.config, or
Add {shell, [{config, "something.config}]}. to your rebar.config
It's not elegant modify everytime your rebar.config but you can use the tuple {sys_config, FilePath}.
{sys_config, "config/sys.config"}.
When you run the command "rebar3 shell", they will load the configuration placed in "config/sys.config"
Related
I'm trying to write erlang first app. It has
https://github.com/emedia-project/erlffmpeg in deps, I have almost the
same Makefile.
When I run erlang shell in erlffmpeg dir and eval README
example, all ok. But When I do it from my project's dir, I get error
like: ucp detect undef. So, my erl shell see the fns from ffmpeg
module, but when i try to eval this fns it seems like shell doesn't know
about inheritant deps of ffmpeg.
I run erl shell with make dev command. In short, it does erl -pa ebin
deps/*/ebin
Seems like i'm missing some knowledge about module loading.
What should I do with this and what you advice me to read?
Thank you!
So, the answer is to use rebar and set the deps like:
{deps, [
{ffmpeg, ".*", {git, "https://github.com/emedia-project/erlffmpeg", "master"}}
]}.
In this case rebar will automatically download all iner dependencies in root deps folder, so the shell with command erl -pa ebin deps/*/ebin will hook up all .beam files.
Big thanks to friendly #erlang members.
Part of setting up my ejabberd server includes running ejabberdctl debug and entering some commands. Instead, I would like to have a file that is executed, but have it run from the same context of the ejabberdctl debug REPL. How can I do this?
You can use the rpc:call command. The Node value is what you see at the debug prompt "name#host".
Also, make sure the escript sets the appropriate cookie value.
Let me clarify, if the debug environment looked like this:
(ejabberd#host)1>
You can create a escript file which looks like this. This updates the log level:
#!/usr/bin/env escript
%%! -sname script1 -setcookie cookie -hidden
main([Level]) ->
rpc:call('ejabberd#host', ejabberd_loglevel, set, [list_to_atom(Level)]).
I have an Erlang application and I can compile it easily and run it by using basho rebar which makes an stand-alone escript executable file. I run it from command line like: ./myapp myconfig.config
My questio is that how can I run it inside Erlang shell. This application has four other applications as dependency. Rebar compile all of the easily. But I need to run this application from inside the shell like:
erl -noshell -name node1#machine -run test start parameter1 -s init stop;
But I don't know in which path I should run it. When I try it in "ebin" folder (where beam files are located), dependencies are not accessible. As I see each dependency applications has it own "ebin" folder.
So how can I run my application by "erl -noshell" command (consider dependency applications)?
Rebar handles all these things automatically.
A typical directory structure for a Rebar-powered OTP application is something like this:
/
src/
ebin/
deps/
dep1/
src/
ebin/
dep2/
src/
ebin/
So, if you're in the root directory of your project, you can point erl to the right place with the -pa argument. To tell it where to find both your application's and its dependencies' BEAM files, try the following:
erl [...] -pa ebin -pa deps/*/ebin
In my startup script, I am starting erlang with:
erl -args_file vm.args
Currently, while trying to run unit tests with rebar eunit is there a way for me to pass custom runtime arguments such as the -args_file option to the erlang process that rebar kicks off? I have searched docs high and low to no avail...
I appreciate the help.
I answered my own question. I use the ERL_FLAGS variable to pass command line args. Here is a snippet from my Makefile:
ERL_FLAGS="-args_file test/conf/vm.eunit.args" ./rebar skip_deps=true eunit
The first method is satisfied with your restriction:
1. in your eunit test function, to use erlang's "os:cmd("erl -name bar -detached arguments")." to start another erlang node. In the arguments, you can insert whatever you want. But eunit's check will be difficult because the test will cross the nodes.
The second methods is to change your restriction:
1. To use "configuremnt file" to pass arguments, and not to use command parameter to pass parameters.
I recently installed Erlang RFC4627 (JSON-RPC) with the debian package. I ran the test server using:
sudo erl -pa ebin
and then at the prompt:
test_jsonrpc:start_httpd().
returned
ok
I tested with http://:5671/ and got the success messages.
When I try to run rabbitmq-http2 however, I get the errors that the readme says are caused by rfc4627's code not being on the erlang search path. How do I put it on the path. I saw something on Dave Thomas's blog which suggested putting the path in the file:
~/.erlang
This didn't seem to work for me (maybe I did it wrong?).
The code module is how you manipulate the path within an application.
The flags -pa that you used in starting the Erlang shell actually refer to a function in this module:
add_patha(Dir) -> true | {error, What}
You are right about the .erlang file in your home directory - it is run at start-up time of the shell and you can add in handy paths.
For an application you can start the shell with a batch file that calls something like this:
erl -pa ./ebin ../../lib/some/path/ebin
The flags behaviour of erl is described here.
For more sophisticated path management you need to get familiar with how OTP release management is done (but I suspect that is a while away for you yet).