[erlang-questions] Escript and spawn

Erik de Castro Lopo <>
Sat Apr 28 03:05:53 CEST 2007


Hi all,

I'm relatively new to erlang and I'm writing lots of small programs
to explore the language. Most of these programs use escript so I can
just run erlang code like I would shell or python.

The problem is that the spawn command doesn't seem to agree with
escript. Here's an example:

    #!/usr/bin/env escript
    
    -module (test).
    -export ([ main/1, new_process/0 ]).
    
    new_process () ->
        io:format ("new_process\n"),
        exit ("Done").
    
    main (_) ->
        spawn (?MODULE, new_process, []),
        timer:sleep (5000),
        ok.

Running this as a script results in:

    Error in File:./spawn_test.erl Line:12 syntax error before: '?'
    Script terminated

but if I comment out the first line (#!/usr/bin/env escript) and compile/
run it in the erlang shell it works as expected.

Can anyone clue me in as to why?

BTW, I'm using escript 4.1 with erlang R11b2 on Ubuntu linux.

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
The difference between a violin and a viola is that a viola
burns longer.



More information about the erlang-questions mailing list