[erlang-questions] open_port vs. unix pipes

Rapsey rapsey@REDACTED
Sun Oct 26 10:50:24 CET 2008


I tried a simple echo.c program:

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>


int main()
{
    char readBuff[1024];
    int numRead = 0;

    while ((numRead = read(0, readBuff, 1024)) > 0)
    {
        write(1, readBuff, numRead);
    }

    return 1;
}

It seems that read returns with 0 immediately and the program exits. Is this
suppose to happen?



Sergej



On Sat, Oct 25, 2008 at 11:05 AM, Rapsey <rapsey@REDACTED> wrote:

> What is the difference for the program that communicates using stdin and
> stdout, if it is opened using open_port from within erlang or with unix
> pipes?
> I'm trying to use open_port with ffmpeg, this works just fine for instance:
>
> cat blabla.mp3 | /opt/local/bin/ffmpeg -f mp3 -i - -acodec libfaac -f flv
> -  > dan.flv
>
> But if I use open_port:
> {ok, Bin} = file:read_file("blabla.mp3"),
> Port = open_port({spawn, "/opt/local/bin/ffmpeg -f mp3 -i - -acodec libfaac
> -f flv -"}, [binary, use_stdio, stream]),
> <<Data:128000/binary, Remain/binary>> = Bin,
> Port ! {Port {command, Data}}
>
> ffmpeg call will fail with:
> pipe:: Error while opening file
>
>
>
> /Sergej
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081026/192bfeb9/attachment.htm>


More information about the erlang-questions mailing list