Re: [LIP] Simple doubt - read from pipe

"Amit Limaye" <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
It does not wait for a enter for you the control is already with the console
try running a shell command on the same line as hello and u will realize :-)

-SIGTERM
amit

----- Original Message -----
From: "Gowri Ramasubramanian" <[email protected]>
To: <linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Sent: Saturday, January 31, 2004 3:20 PM
Subject: [LIP] Simple doubt - read from pipe


> 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)
>         {
>                 file://parent
>                 close(fd[0]);
>                 write(fd[1], "hello", 5);
>         }
>         else
>         {
>                 file://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
> _______________________________________________
> linux-india-programmers mailing list
> linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/linux-india-programmers



-------------------------------------------------------
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.