[erlang-questions] erlang port and C executable
Per Hedeland
per@REDACTED
Sun Nov 23 22:11:10 CET 2008
"Edwin Fine" <erlang-questions_efine@REDACTED> wrote:
>
>Thanks for the offer, but it's working correctly NOW. I did post the C and
>Erlang code (that is, the code that works) in this thread; if you are bored
>sometime and want to critique it, I'd appreciate it.
It seemed fine - the C side did what a large variety of *nix programs
do, read stdin until EOF and then exit - which works very well with the
port mechanism as-is.
> The symptom was that
>the spawned echo program was not closing down. I now think that what
>happened is that it got input and was trying to write output, but the Erlang
>port closed before it could do that, so it was hung on the output pipe.
That shouldn't happen either. The magic of *nix pipes does its job in
that direction too - if there are no processes that have the read side
of a pipe open (and there won't be if Erlang has closed the port),
trying to write to it will deliver a SIGPIPE to the writer, which will
promptly kill it unless it has taken steps to prevent that.
> When
>I did a flush() in the shell later I got more input than I expected, so
>maybe that was it.
Sounds more as if you didn't actually close the port when you thought
that you did it.
>> Perhaps, but they can't do everything for you - it's a trivial program
>> to write, except that there's a lot of little things that it should do
>> in different ways depending on your needs, which means that it will
>> become quite complex to use if it should cover everyone's needs.
>
>
>So it's not actually that trivial ;)
If you only have a single need it is trivial.:-)
>> E.g. does it need to "proxy" input and/or output for the child program?
>> Should it grab its stdio for this or use some other file descriptors?
>> What "protocol" should it talk on the port pipes back to Erlang? Etc.
>>
>
>Those are all excellent points. My desire would be for a wrapper that allows
>one to reliably start, stop, and exchange data via stdin and stdout with a
>Unix/Linux program such as gnuplot.
As far as I know gnuplot in interactive mode will exit as soon as it
sees EOF on stdin - it shouldn't need a wrapper. Though I guess you
might accidentally feed it some data that takes "forever" to plot.
--Per
More information about the erlang-questions
mailing list