Erlang ports and Perl

Sean Hinde <>
Wed Feb 23 18:27:51 CET 2000


This one seems to work. Thanks for all your answers.

Sean

-----Original Message-----
From: Shawn Pearce [mailto:]
Sent: 23 February 2000 16:34
To: 
Subject: Re: Erlang ports and Perl


Sean,

Perl output is typically line-buffered by default by Perl.  This means
that the underlying OS will not receive any information to pass onto
another program (such as Erlang) unless a newline ("\n") is printed in
Perl.  Try doing the following before your while(1) loop starts:

	select((select(STDOUT),$| = 1)[0]);
	select((select(STDERR),$| = 1)[0]);

to unbuffer both the STDOUT and STDERR streams and see if that makes
a difference to your little program.

Sean Hinde <> scrawled:
> Hi all,
> 
> I'm having a little difficulty with using a perl script as a port program:
> 
> #!/usr/local/bin/perl
> while(1) {
> $cmd = <STDIN>;
> print STDERR "Received OK";
> print "ok";
> print STDERR "Sent";
> }
> 
> My erlang port program:
> 
> Port = open_port({spawn, "perlscript"}, [stream]),
> Port ! {self(), {command, "hello"}},
> receive
>   Data ->
> 	Data
>   after 10000
> 	timedout
> end
> 
> The result of this is that perl receives the hello message and prints
> "Received OK" and "Sent" on stderr, but my erlang process never receives
> "ok". Tracing confirms that the hello message is sent to the port but
> nothing is received. Using an equivalent C program as the port program
with
> the same erlang code works fine.


--
Shawn.

  ``If this had been a real
    life, you would have
    received instructions
    on where to go and what
    to do.''



More information about the erlang-questions mailing list