Call a compiled Beam module

Ulf Wiger etxuwig@REDACTED
Thu May 8 10:35:41 CEST 2003

On Thu, 8 May 2003, Jilani Khaldi wrote:

>>Good day,
>>Please try:
>That's Ok, but it loads only the module but not the "*.gif"
>images inside "c:/abc" that the module uses, and it aborts.
>Any idea?

An OTPish way of doing things would be to organize your code
into applications like in the OTP code tree:



You can then use the function code:priv_dir(myapp) and find
$MYROOT/lib/myapp-1.0/priv/. From there, you can e.g. slap
on an imgs/ subdirectory and fetch your files.

Another method would be to maintain a variable pointing to
your personal files. This can be done in many ways.

- If you want to specify an OS environment variable, you can
  do so, and fetch the location using os:getenv(Variable)

- If you want to specify the location as an argument to
  the 'erl' command, you are free to do so:

#: erl -mydir /foo
Erlang (BEAM) emulator version [source] [threads:0]

Eshell V5.2.3.3  (abort with ^G)
1> init:get_argument(mydir).

- You can store a value in Mnesia, of course

You can also use code:which(?MODULE) in your code to find
the location of your .beam file. This is a questionable
tactic, since it will be misleading if the module has been
loaded from a patch directory.

I'm sure there are other, perhaps better, ways, but those
were some alternatives off the top of my head.

Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes

More information about the erlang-questions mailing list