Why port doesn’t provide exit code when it’s closed?

Basically the title. I can’t find any information on how to get the exit code of a port when it’s closed, whether from Elixir or when it’s closed by itself (for some other reason).

System.cmd function returns the exit code of the process, so why don’t ports provide this?

Or am I missing something?

1 Like

During use of a port opened using {spawn, Name}, {spawn_driver, Name}, or {spawn_executable, Name}, errors arising when sending messages to it are reported to the owning process using signals of the form {‘EXIT’, Port, PosixCode}. For the possible values ofPosixCode, see file(3).

That’s what the erlang port docs say. So I’d expect you get the error code.


My bad. I missed the mention to Erlang docs.

There’s also a :exit_status option, when given it will report back the exit code when the process exits abnormally.