Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!cbdkc1!cbnap!cbneb!adm From: adm@cbneb.UUCP Newsgroups: net.unix Subject: Re: Dissimilar Program Interaction? Message-ID: <5263@cbneb.UUCP> Date: Thu, 2-Oct-86 11:02:24 EDT Article-I.D.: cbneb.5263 Posted: Thu Oct 2 11:02:24 1986 Date-Received: Sat, 4-Oct-86 05:58:07 EDT Sender: adm@cbneb.UUCP Organization: AT&T Bell Laboratories, Columbus, OHIO Lines: 62 Nf-ID: #R:uiucdcsb:-1930005400:cbneb:230300001:000:1761 Nf-From: cbneb!srini Oct 2 10:39:00 1986 /***** cbneb:net.unix / uiucdcsb!kadie / 4:53 am Oct 2, 1986 */ > Unfortunately I don't know how to > connect the pipe(s) to standard input and standard output > of the sub-program. > Also this does not permit fscan and fprint. /* The following code does not do any error checking */ int fildes[2]; int pid; int c; pipe (fildes); if( (pid = fork()) == 0 ) { /* CHILD */ close(0); dup (fildes[0]); /* Redirect stdin of child from parent*/ close(1); dup (fildes[1]); /* Redirect stdout of child to parent */ close (fildes[0]); /* Don't need these anymore */ close (fildes[1]); exec_ (the_child); /* * Now when the child writes to its file descriptor 1, it is * actually going down the pipe's write end. Likewise its read * on file descriptor 0 is actually reading from the read end of * the pipe. */ } /* PARENT */ while(read(fildes[0], &c, 1)) { munch (c); } /* * This entire sequence of code can be repeated in an intelligent * fashion for multiple child processes. You can simply poll the * various pipes by setting N_DELAY on the read end of the pipes * using fcntl(), and looping around them. * * Caveat : Don't use fscanf (buffered i/o) on pipes as the child's * buffering mechanism might not be exactly what you want. * Follow the low-level 'read' with 'sscanf', which might * be more deterministic. */ -------------------------------------------------------------------------------- S. Srinivasan UUCP: {cbosgd,ihnp4}!cbneb!srini [AT&T Bell Labs,MiddleOfTheRoadOhio] -------------------------------------------------------------------------------- Now stick that in your pipe and smoke it !