Erl Command - Execute Erlang Runtime System

Learn how to execute Erlang runtime system commands with

Erl Command

The erl command is the primary interface for starting and interacting with the Erlang runtime system. It allows developers to execute Erlang code, load compiled modules, and manage Erlang processes from the command line.

Starting the Erlang Runtime System

When you run the erl command without any arguments, it typically starts an interactive Erlang shell (REPL). This is useful for testing small code snippets, exploring Erlang features, and debugging.

Executing Compiled BEAM Files

You can execute compiled Erlang code, which is distributed as .beam files, using the erl command. This is often done to run specific applications or modules without entering the interactive shell.

# erl
#
# Start Erlang runtime system

# Execute compiled BEAM file (helloworld.beam)
erl -noshell -s helloworld start -s init stop

Running Code from the Command Line with -eval

For simple tasks or quick scripts, the -eval option allows you to execute Erlang expressions directly from the command line. This is a convenient way to run short pieces of code without creating separate files.

# Run code from the command line
erl -noshell -eval 'io:fwrite("Hello, World!\n"), init:stop().'

Understanding Common Options

  • -noshell: Prevents the interactive Erlang shell from starting, which is useful when running scripts or specific commands.
  • -s module function [args]: Starts a module and calls a function with optional arguments.
  • -eval 'expression': Evaluates an Erlang expression.
  • -s init stop: Ensures that the Erlang runtime system exits gracefully after the specified tasks are completed.

Further Resources