Skip to content

Instantly share code, notes, and snippets.

@colejhudson
Last active March 11, 2021 07:26
Show Gist options
  • Save colejhudson/1027ee354bb4c684948fc011026a7e1c to your computer and use it in GitHub Desktop.
Save colejhudson/1027ee354bb4c684948fc011026a7e1c to your computer and use it in GitHub Desktop.
Lots of nonsense involved in running and/or deploying an Erlang program, this is a small note on how to run one immediately.
% There are two ways to run this file. The first
% is as follows:
%
% $ erlc main.erl
% $ erl -noshell -s main init
%
% Here, `erlc` is compiling the erlang file to beam
% bytecode and writes said bytecode to 'main.beam'.
% Then erl, by default looking in the immediate
% directory, loads any beam files, looks for the
% main module, and invokes it's init process.
%
% The second method uses `escript` and requires that
% there be a 'main' function. Given that an erlang
% file can be executed as shown:
%
% $ escript main.erl
-module(main).
-export([init/0]).
init() ->
ok = io:format("Success!"),
% init:stop(), erlang:halt(0), and stop(self()) are
% all equally valid ways of exiting an erlang program.
init:stop().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment