Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!munnari.oz.au!murdu!viccol!timcc From: timcc@csv.viccol.edu.au (Tim Cook) Newsgroups: comp.unix.wizards Subject: How do I get EOF from a pipe I created? Keywords: pipe fork dup2 fdopen Message-ID: <6366.26be9bd9@csv.viccol.edu.au> Date: 7 Aug 90 15:45:45 GMT Organization: Computer Services, Victoria College, Melbourne Lines: 31 I am having a bit of fun writing a utility that parses the output of a command that it exec's in a subprocess. What I am doing is basically (minus error checking): int pipe_descriptors[2] ; pipe (pipe_descriptors) ; if (fork ()) { /* Subprocess */ dup2 (pipe_descriptors[1], 1) ; execl ("/dir/command", "command", "arg", 0) ; /*NOTREACHED*/ } /* Parent continues here */ pipe_stream = fdopen (pipe_descriptors[0], "r") ; while (! feof (pipe_stream)) { fgets (buffer, sizeof (buffer) - 1, pipe_stream) ; /* Parsing of what is in "buffer"... */ } Well, I get the output of "command" coming through on "pipe_stream", but I don't get end-of-file. The fgets call just blocks when there is nothing left in the pipe (and not because the last record output by "command" was not terminated by a newline). Can anyone help me set this up so that I see EOF? Can anyone also tell me how to have the parent process retain control of the tty that it was invoked on? At the moment, the shell regains control when the process exec-ed by the child completes, indicating that the child got control.