Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!maverick.ksu.ksu.edu!zaphod.mps.ohio-state.edu!wuarchive!rex!ames!skipper!bruno From: bruno@skipper.dfrf.nasa.gov (Bruno Chenet) Newsgroups: comp.unix.programmer Subject: LOST in a PIPE Message-ID: <782@skipper.dfrf.nasa.gov> Date: 25 Feb 91 16:24:00 GMT Distribution: usa Organization: NASA Ames-Dryden FRF, Edwards, CA Lines: 68 To anybody that understands fork(), system() or popen() I am sending the command "tar tvf /dev/rst0" to list the content of a tape drive. I want to be able to grap each file description that shows up on my screen as soon as possible since I want to display it in my own X-window. I tried to redirect the output to a file but then I cannot read this file as long as information is redirected to it. (And this can take 5 or more minutes when I am listing a full tape or CD). I cannot afford to let the user waits that long. Originally I was sending the command using a "popen()" as follow: ********************** sprintf(cmdline," %s ", "tar tvf /dev/rfd0"); if ((fp = popen(cmdline, "r")) == NULL) printf("popen error"); try #1: /* while ((fgets(line, MAXLINE, fp)) != NULL) { n = strlen(line); if (write(1, line, n) != n) printf("data write error|n"); */ try #2: /* while ((ch = fgetc(fp)) != EOF) { if (ch == '\n') { buf[i++] = ch; fprintf(stderr," %s",buf); i=0; } else buf[i++] = ch; } */ ********************** I should be able to read the stderr stream but I don't know how to do it. I think that I need to use fork processing and read the stderr until a EOL is reached. At this point I should be able to grab this line and put it in some kind of buffer to be able to display it in my window and then give the control to the tar command again and so on... I have also another problem of the same type: What happen if I send a command that is not right. The system will answer with some kind of error message send to stderr. I need to grab this message and display it in in my "report window" (I am trying to build a kind of front end to the UNIX system using the X-Window environment so that UNIX becomes more "user friendly"). Should I use "popen()", "system()", "shell scripts" or just "fork()" ? Please, I would take any ideas that would help me solve these problems. Thank you for your time, Bruno Brought to you by Super Global Mega Corp .com