home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!cs.utexas.edu!mercury.unt.edu!ponder.csci.unt.edu!gene
- From: gene@ponder.csci.unt.edu (Gene De Lisa)
- Subject: need help reading from a child
- Message-ID: <1992Aug21.202934.3736@mercury.unt.edu>
- Sender: usenet@mercury.unt.edu (UNT USENet Adminstrator)
- Organization: University of North Texas, Denton
- Date: Fri, 21 Aug 1992 20:29:34 GMT
- Lines: 47
-
-
- This code hangs on the read (or fread). I simply want to
- exec the child and read both its stdout and stderr.
- suggestions?
- (previous imbrications commented out)
-
-
- if (pipe(pipefds) < 0) {
- perror("pipe");
- return(NULL);
- }
-
- if ((pid = fork()) < 0) {
- perror("fork");
- return(NULL);
- }
- if (pid == 0) {
- #if 0
- close(0);
- close(1);
- close(2);
- for(j=3; j<getdtablesize(); j++)
- close(j);
- #endif
- dup2(pipefds[0],0);
- dup2(pipefds[1],1);
- dup2(pipefds[1],2);
- execvp(*args, args);
- perror("on execvp");
- exit(-1);
- }
- if ((fp = fdopen(pipefds[0], "r")) == NULL) {
- perror("fdopen");
- }
-
- /*while ((n=read(pipefds[0], &buf[count], sizeof(buf))) > 0) */
-
- while ((n=fread(&buf[count], sizeof(char), sizeof(buf), fp)) > 0) {
- count += n;
- printf("c=%d\n", count);
- }
-
- fclose(fp);
- while (wait((int *) 0) != pid)
- ;
-
-
-