Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!uwm.edu!lll-winken!elroy.jpl.nasa.gov!decwrl!shelby!portia!bugboy From: bugboy@portia.Stanford.EDU (Michael Frank) Newsgroups: comp.unix.questions Subject: Re: Need a 2-way alternative to popen() Message-ID: <9655@portia.Stanford.EDU> Date: 1 Mar 90 00:47:31 GMT Sender: Michael Frank Reply-To: bugboy@portia.Stanford.EDU (Michael Frank) Organization: Stanford University Lines: 23 Thanks to everyone who sent me help on ways to set up a 2-way alternative to popen(). Some of you didn't hear this directly from me, because the email bounced. Anyway, I've put together here the core elements of the way to do it with pipe() instead of popen(): int p1[2], p2[2]; /* Two pairs of fd's */ pipe(p1); pipe(p2); /* Create the two pipes */ if (fork() == 0) { /* - in child process - */ char * args[2]; /* array of args for command */ args[0] = "/bin/csh"; /* set up the args for the call */ args[1] = NULL; /* (array is NULL-terminated) */ dup2(p1[0],0); /* copy p1's read end to stdin */ dup2(p2[1],1); /* copy p2's write end to stdout */ execv(args[0], args); /* call the csh command */ } tochild = p1[1]; fromchild = p2[0]; /* Parent's links to it */ Of course, to be neat about it you should also close the unused fd's and check the system calls for errors. But these are the central parts. Thaks again! Mike