open_port function problem.

Ingela Anderton ingela@REDACTED
Fri Dec 19 10:13:49 CET 2003

Joachim Durchholz wrote:
> Chenniappan,Dhanasekaran [DBA] wrote:

> > sending 26. Evenn the example foo also reflect the same
> > resullt. Please
Humm ... my interpretation of sending foo is
that the atom foo was sent, but maybe I was reading to much in to it.
If what was sent was "foo"  and the system used is windows
you have a valid point below.

> You're probably working on a Windows system, and the port got opened in 
> text mode.
> Under Windows, text mode file handles will interpret code 10 (newline) 
> as line end (and store the bytes 13 and 10, carriage return and newline, 
> to establish conformance with Windows conventions). Code 26 is 
> Control-Z, which means end-of-file (this is a really ancient convention 
> but kept for compatibility).
> To get rid of these effects, open the port in "binary" mode; in this 
> mode, no translation takes place.
> Text mode interpretation may happen both on the sending and receiving 
> end of the pipe. IOW you should not only check the Erlang side of 
> things, but also the C side.
> Actually, when I think of it, it's most likely that you're just using 
> the stdin handle in the C program, which is always opened in text mode 
> for you; you have to change its mode (not sure how to do this, you're 
> probably in for an extensive search in MSDN).
> Keep us posted on results, this might be an interesting information 
> snippet to be added to the Erlang documentation :-)
Well yes this is true, maybe we should add something about the wonderful
world of windows to the documentation!

/m.v.h Ingela

Ericsson AB - OTP team

More information about the erlang-questions mailing list