Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!uvaarpa!mmdf From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.perl Subject: problem redirecting STDOUT to pipe Message-ID: <1990Jul16.161925.9869@uvaarpa.Virginia.EDU> Date: 16 Jul 90 16:19:25 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: worley@compass.com Organization: The Internet Lines: 27 X-Name: Randal Schwartz The short answer, which may lead you to more insight, is that you also need to think of the stdout of the "dd" command. [...] The problem is that this loses... You have to always put STDOUT on fd 1, because otherwise if you exec something its output will go into never-never land. The proper way to handle pipes and redirection is to first create a pipe pair (which goes on fd's 7 and 8, say), then fork, then each process closes stdin/stdout/whatever and dup's the input or output side of the pipe into the correct fd's, and then both close fd's 7 and 8 (to clean up). With this method, each process can put either end of the pipe on whatever fd's it wants. While we're at it, what's the method for creating a pipe pair in Perl? I can't find anything in the manual that does not also cause forking. I'm sure this has been discussed before, but I don't remember the answer and now I'm in the throes of a "redirect both STDIN and STDOUT to a subprocess" program... Dale Worley Compass, Inc. worley@compass.com -- "If you could have any amount of money... How much would you want?" "All of it."