[erlang-questions] EOF to external program

Tony Rogvall <>
Wed Nov 17 09:49:04 CET 2010


Hi Matthias!

This should probably be turned into a EEP, "active mode support for spawn driver"
Any takers ;-) Why not add packet_parser support while at it?

I definitely vote for this (initial) suggestion.

/Tony


On 17 nov 2010, at 05.44, Matthias Lang wrote:

> Hi,
> 
> None of the people who know a definite answer have answered.
> 
> One likely reason for ports being the way they are is that whoever
> first implemented them intended them for running external programs
> specifically written to work with Erlang. I.e. the general case of
> running Erlang-oblivious code wasn't considered, or was considered as
> something to be done through a wrapper, or was thrown on the "worry
> about that later" pile. And nobody since then has been both
> sufficiently annoyed and sufficiently skilled to remove that
> restriction.
> 
> Using 'netcat' (my suggestion) is a pretty desperate workaround, i.e.
> it works, but it's not pretty. 
> 
> A proper fix would be to give ports a similar interface to gen_tcp in
> {active, false} mode, something like:
> 
>   {ok, Port} = os_process:open("wc /dev/zero", [binary, {active, false}]).
>   {ok, Bin} =  os_process:recv(Port, 0).
>   {ok, Last_bin, Exit_value} = os_process:close(Port).
> 
> it probably wouldn't hurt supporting {active, once} too.
> 
> Matt
> 
> ----------------------------------------------------------------------
> 
> On Friday, November 05, Timo Lindemann wrote:
>> Hello erlangers,
>> 
>> I like to use external programs, so I thought I could use ports a lot. I
>> fail to understand one detail about ports: Why can one not close the write
>> end (such that the connected external program registers an EOF on its stdin
>> descriptor)?
>> 
>> I dug around the web some, and found that this has stumped other people in
>> the past, with suggestions about using netcat to work around that problem,
>> to writing a wrapper that parses the data for some marker the process would
>> send to the external program signalling EOF and have the wrapper close the
>> write end.
>> 
>> Why is there NO way in erlang to let a program know the input's data has
>> ended *and* fetching its response *and* getting its (normal) exit status?
>> port_close/1 will normally instantly kill the external program.
>> 
>> Omitting this feature severely limits the things one can do with ports. awk
>> will not process its END clause, wc will never exit, ... if there's no EOF
>> to be found. There's a lot of programs waiting for stdin to close.
>> 
>> So please, what's the reason for not allowing this? Will this be added
>> sometime later on? Or have I just not found a way to do it?
>> 
>> All the best
>> -T.
>> 
>> -- 
>> Timo Lindemann
>> Software Systems Engineer
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
> 

"Have run Make so many times I dunno what's installed anymore"



More information about the erlang-questions mailing list