Copyright Digital Equipment Corp. All rights reserved.

Example

       parent.c
       ========

       #include <stdio.h>
       #include <string.h>
       #include <unistd.h>

       int decc$set_child_standard_streams(int, int, int);

       main()
       {
           int fdin[2], fdout[2], fderr[2];
           char msg[] = "parent writing to child's stdin";
           char buf[80];
           int nbytes;

           pipe(fdin);
           pipe(fdout);
           pipe(fderr);

           if ( vfork() == 0 ) {
          decc$set_child_standard_streams(fdin[0], fdout[1], fderr[1]);
             execl( "child", "child" );
           }
           else {
               write(fdin[1], msg, sizeof(msg));
               nbytes = read(fdout[0], buf, sizeof(buf));
               buf[nbytes] = '\0';
               puts(buf);
               nbytes = read(fderr[0], buf, sizeof(buf));
               buf[nbytes] = '\0';
               puts(buf);
           }
       }

       child.c
       =======

       #include <stdio.h>
       #include <unistd.h>

       main()
       {
           char msg[] = "child writing to stderr";
           char buf[80];
           int nbytes;

           nbytes = read(0, buf, sizeof(buf));
           write(1, buf, nbytes);
           write(2, msg, sizeof(msg));
       }

       child.com
       =========

       $ read sys$command s
       $ write sys$output s
       $ write sys$error "child writing to stderr"

     This example program returns the following for both child.c and
     child.com:

       $ run parent
       parent writing to child's stdin
       child writing to stderr

     Note that in order to activate child.com, you must explicitly
     specify execl("child.com", ...) in the parent.c program.