/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ /* decc$set_child_standard_streams_example.c */ /* Demonstrate the use of decc$set_child_standard_streams */ /* with both an executable child and a command file child */ #include #include #include int decc$set_child_standard_streams(int, int, int); const char *exe_child = "decc$set_child_standard_streams_child.exe" ; const char *com_child = "decc$set_child_standard_streams_child.com" ; char msg[] = "parent writing to child's stdin"; void call_child(const char *child_name) { char buf[80]; int nbytes; int fdin[2], fdout[2], fderr[2]; pipe(fdin); pipe(fdout); pipe(fderr); printf("Parent is calling %s\n", child_name) ; if ( vfork() == 0 ) { decc$set_child_standard_streams(fdin[0], fdout[1], fderr[1]); execl( child_name, "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); } } main() { call_child(exe_child) ; /* Call teh executable child */ call_child(com_child) ; /* and the same for the com file */ }