[erlang-questions] open_port, windows, message order

Viacheslav V. Kovalev kovyl2404@REDACTED
Thu Jun 4 21:22:31 CEST 2015


Hi list! While fixing rebar3 windows-specific bugs I've encountered
pretty odd (at least for me) thing.
See below.

```
1> file:get_cwd().
{ok,"C:/Users/vkovalev/Documents/rebar3"}
%% Yup, I'm in rebar3 project root directory.

2> Cmd = {spawn, "cmd /q /c git log -n 1 --pretty=format:\"%h\n\" "}.
{spawn,"cmd /q /c git log -n 1 --pretty=format:\"%h\n\" "}
3> Opts = [exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide].
[exit_status,{line,16384},use_stdio,stderr_to_stdout,hide]

%% This is one of things rebar3 does when building something (itself,
for example).

4> open_port(Cmd, Opts).
#Port<0.489>
5> flush().
Shell got {#Port<0.489>,{exit_status,0}}
Shell got {#Port<0.489>,{data,{noeol,"00e2a3b"}}}
%% Oops. Note the messages order.
```

Rebar stops to receive messages right after it received `{exit_status,
_}` and then it just misses last message.

1. So does erlang define strict order of this messages, incoming from
port? I mean `data` message and `exit_status`. If it doesn't,  how can
I reliably detect that port command is completely done?
2. What if I'll enable `eof` flag? It obviously should arrive only
after all data messages received. But can it occur that in some
certain cases I'll not receive `eof`? For example, when port program
crashes some specific way? Or is it guaranteed that I'll receive `eof`
if I ask for it?

Sorry, if my thoughts a bit muddled.
Thanks!



More information about the erlang-questions mailing list