a question about pipe comp.unix.programmer

a question about pipe comp.unix.programmer

Post by Dongchul L » Sat, 26 Aug 1995 04:00:00



I'm not a UNIX expert, but I have to do some simple programming in
UNIX. What I want to do is to feed the data from the parent to
the child process. I found out an example in which the parent process
reads the data that was produced by the child process.
What I need is an opposite procedure -- i.e., the parent writes to
a pipe and the child reads from the pipe.
This can be done using popen and pclose pair:

        p = popen();
        while ((n = fread(buf,1,sizeof(buf),fp))) fwrite(buf,1,n,p);
        pclose(p)

Note that all that I know at the time of calling popen is a file
pointer, fp, which had been obtained from fopen, tmpfile, etc.
I need to do this using fork and pipe instead of popen.
Could someone kindly show me how I can do this?
-dongchul

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


= Yale University         | (203) 432-6288            =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 
 
 

1. a question about pipe comp.unix.programmer

I'm not a UNIX expert, but I have to do some simple programming in
UNIX. What I want to do is to feed the data from the parent to
the child process. I found out an example in which the parent process
reads the data that was produced by the child process.
What I need is an opposite procedure -- i.e., the parent writes to
a pipe and the child reads from the pipe.
This can be done using popen and pclose pair:

        p = popen();
        while ((n = fread(buf,1,sizeof(buf),fp))) fwrite(buf,1,n,p);
        pclose(p)

Note that all that I know at the time of calling popen is a file
pointer, fp, which had been obtained from fopen, tmpfile, etc.
I need to do this using fork and pipe instead of popen.
Could someone kindly show me how I can do this?
-dongchul

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


= Yale University         | (203) 432-6288            =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

2. Simple date Mathematics

3. comp.unix.questions comp.unix.misc comp.unix.sys5.r3

4. Help reset my modem

5. Why can't I post to comp.unix.shell, comp.unix.programmer?

6. problem with modem manager

7. comp.sys.hp comp.sys.sgi comp.sys.sun comp.unix.ultrix comp.unix.wizards

8. resolution crash

9. comp.unix.shell comp.sys.sun.admin comp.unix.questions

10. comp.unix.wizards comp.lang.c comp.sys.sun alt.unix.wizards alt.unix.wizards.free

11. comp.unix.programmer FAQ question

12. Welcome to comp.unix.questions and comp.unix.wizards [Monthly posting]