Remotely loading Erlang modules by copy-pasting

13 Jul 2023 13:59 erlang

If you want to replace an Erlang module on a remote node, but you’re unable to copy files to it, and you’re unable to make RPC calls to it, but you can get a remote console, here’s what you do:

Start a local erlang shell, then:

Mod = foo.

% Load the module locally.
{module, Mod} = code:load_file(Mod).
{Mod, Bin, File} = code:get_object_code(Mod).
rp(Bin).  % Copy the output from this.

On the remote console:

Mod = foo.
File = "foo.erl".   % from above.
Bin = <<...>>.  % Paste the output from above.
code:load_binary(Mod, File, Bin).