eclipseerlangerlide

Erlide: how to set start module in run configuration?


I have problem with setting start module and function in "Run configuration" I'm doing it that way: "Run -> Run Configuration" and in "start" section I'm setting Module: mod, Function: hello

my code:

-module(mod).
-export([hello/0]).
hello()-> io:format("42").

Now, when I hit "Run" I would like mod:hello() to be execute automatically, but it doesn't work. What am I doing wrong?


Solution

  • The code does get executed...

    When you hit "Run", mod:hello() does get executed. The thing is, the execution of mod:hello() is meant for system initialization, like loading library code and initializing looping states. The side effect of mod:hello(), which is the string "42" as stdout will not be reflected in your Eclipse console. To prove my point, we can create some more explicit and more persistent side effects, like creating a file in the file system called output_file.txt. Change mod.erl to something like this:

    -module(mod).
    -export([hello/0]).
    
    hello() ->
        os:cmd("touch output_file.txt").
    

    Hit "Run", and you will find a output_file.txt file being created under your workspace directory. This is an evidence for the execution of mod:hello().

    To achieve what you want...

    In an Unix shell:

    $ erlc mod.erl 
    $ erl -noshell -s mod hello -s init stop
    42