views:

251

answers:

3
([email protected])8> spawn([email protected], tut, test, [hello, 5]).

I want to spawn a process on bar.del.com which has no file system access to foo.hyd.com (from where I am spawning the process), running subroutine "test" of module "tut".

Is there a way to do so, w/o providing the [email protected] with the compiled "tut" module file?

A: 

You can send the local code to the remote node:

> {Mod, Bin, File} = code:get_object_code(Module).
> rpc:call(RemoteNode, code, load_binary, [Mod, File, Bin]).
Zed
+3  A: 

You can use the following function to load a module at remote node without providing the file itself:

load_module(Node, Module) ->
    {_Module, Bin, Filename} = code:get_object_code(Module), 
    rpc:call(Node, code, load_binary, [Module, Filename, Bin]).

As noted in code:load_binary/3 Filename argument is used only to track the path to module and the file it points to is not used by local node_server.

gleber
A: 

I'm interpreting your question as a desire to not copy the *.beams from your filesystem to the remote file system.

If you are just testing things you can use the nl(Mod) call in the erl shell to load the module on all (currently) known nodes. That is, those that show up in nodes().

This will send the code over and load it from the memory copy, it will not store it in the remote filesystem.

You can also start the remote node using the slave module. A slave accesses its master's filesystem and code server. Ordinary auto-loading will then make sure the module exists in the slave when you call your test:tut/2 function.

Christian