[LIP] Simple doubt - read from pipe

Gowri Ramasubramanian <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
Hi All,

Below is the normal pipes example code.

#include <stdio.h>
#include <stdlib.h>

int main()
{
        int fd[2];
        pid_t pid;
        int n;
        char greet[12];

        if(pipe(fd) < 0)
        {
                printf("error\n");
                exit(2);
        }
        if((pid = fork()) < 0)
        {
                printf("error\n");
                exit(1);
        }
        else if(pid > 0)
        {
                //parent
                close(fd[0]);
                write(fd[1], "hello", 5);
        }
        else
        {
                //child
                close(fd[1]);
                n = read(fd[0], greet, 12);
                write(1, greet, n);
        }
        close(fd[0]);
        close(fd[1]);
        exit(0);
}

The problem I have in this is, when "hello" is printed on stdout, it waits
for '\n' an enter key from me before it gives back the command prompt.  
I don't want this to happen.  I don't understand why it is happening also.  
The solution should be simple but doesn't strike to me.

If anyone of you could help me out.

Thanks.
Gowri


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.