What's the difference between code:add_path and using -pa on the command line?

StackOverflow https://stackoverflow.com/questions/20570508

  •  01-09-2022
  •  | 
  •  

Question

This is my .erlang file:

code:add_path("/home/root/projects/myapp/ebin").
code:add_path("/home/root/projects/esmtp/ebin").
application:load(esmtp),
application:set_env(esmtp, smarthost, {"localhost",25}),
application:set_env(esmtp, default_from, "<stuff>"),
application:start(esmtp).

When I run:

erl -boot myapp 

it fails:

{"init terminating in do_boot",{'cannot get bootfile','myapp.boot'}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()

But if I run:

erl -boot myapp -pa /home/root/projects/myapp/ebin

It works fine. That leads me to believe that -pa on the command line is treated differently than code:add_path() in the .erlang file. I know the .erlang file is in effect, because esmtp loads and runs correctly. What's the difference between -pa and code:add_path()?

Était-ce utile?

La solution

The .erlang file is read and executed after the boot file is loaded, so the path has not been added when erlang is looking for the boot file.

The -pa on the other hand is added before the vm starts to look for the boot file so then it is found.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top