erlc Verified current stable Not installed? Programming

Erlc / Compile And Run Sequential Erlang Program

Compile And Run Sequential Erlang Program

Compile and run an Erlang program in sequence.

$
Terminal
erlc <path/to/file1 path/to/file2 ...> && erl -noshell '{mymodule:myfunction(arguments)}, init:stop().'

When To Use

When testing Erlang modules requiring procedural compilation and execution.

Pro Tip

Use -W to enable warnings during compilation for better debugging.

Anatomy of Output

Understanding the result

Compiling files: file1.erl, file2.erl... Compilation Status

Indicates the files being compiled.

Compilation successful: 0 error(s) Compilation Result

Confirms success in compilation without errors.

Running function in module: mymodule with arguments {'arg1'} Execution Status

Specifies the function being executed with arguments.

Power User Variants

Optimized versions

erlc -W file1.erl file2.erl && erl -noshell -s mymodule myfunction -s init stop

Enable warnings during compilation and run function.

Troubleshooting

Common pitfalls

Error: Could not compile file1.erl: undefined function.

Solution: Check and define or correct the function used.

No such module: mymodule

Solution: Ensure correct module name and compilation.

Runtime error: bad argument.

Solution: Validate arguments being passed to the function.

Command Breakdown

What each part is doing

erlc
Base Command
The executable that performs this operation. Here it runs Erlc before the shell applies any redirect operators.
<path/to/file1 path/to/file2 ...>
Input Files
The file path or paths supplied to this command.
{mymodule:myfunction(arguments)}
mymodule:myfunction(arguments
The value supplied for mymodule:myfunction(arguments.
-noshell
Command Option
Tool-specific option used by this command invocation.

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.