[erlang-questions] escript cutting output

Matthias Lang <>
Fri Nov 18 13:50:21 CET 2011


On Friday, November 18, Tim Watson wrote:

> Have you tried this:
> 
> S = self(),
> spawn_link(fun() -> io:format(Fmt, Data), S ! finished end),
> receive
>     finished ->
>         halt(0);
>     _Other -.
>         halt(1)
> end.
> 
> This is a different situation to the one Ulf was describing in that thread
> I think.

You've posted a "solution" which doesn't even compile. 

Nor have you even attempted to explain how this could possibly make a
difference. Fixing it up and applying it to Samuel's problem, like this:

  #!/usr/bin/env escript
  %% Example: http://xkcd.com/386/
  main(_) ->
    S = self(),
    spawn_link(fun() -> 
       io:format("~p~p~n", [lists:duplicate(100000, $a), b]),
       S ! finished 
    end),
    receive
      finished ->
          halt(0);
      _Other ->
          halt(1)
    end.

produces exactly the same behaviour as Samuel reported, i.e. it emits
a string which does not end in 'b'.

Matt




More information about the erlang-questions mailing list