Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Reopening stdin Message-ID: <8688@star.cs.vu.nl> Date: 8 Jan 91 19:17:01 GMT References: <5200@trantor.harris-atd.com> <8685@star.cs.vu.nl> <5208@trantor.harris-atd.com> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 28 In article <5208@trantor.harris-atd.com>, chuck@trantor.harris-atd.com (Chuck Musciano) writes: )... )> main() )> { )> int fd, i; )> )> close(0); )> fd = open("/etc/passwd", 0); )> dup2(fd, 0); )> i = system("cat"); )> exit(i & 0377 ? i | 0200 : i >> 8); )> } )... ) I checked dup2(), and it is returning 0, as you would expect. In the )case of dup2(0, 0), I tried closing stdin, calling open(), and verified )that I got 0 as the descriptor. I then skipped the dup2 call, called )system(), and it still failed! What about this: note that in the example I forgot a close(fd) statement after the dup2() call; now I expect that you did _not_ forget it in _your_ program, in which case you are closing stdin yourself again! If this still doesn't explain it, could you post or email a minimal piece of code that shows the problem? -- nlp@berlin.mt.cs.cmu.edu: "I heard that an Awk was spotted in Sherwood forest." rmk@frog.UUCP (Rick Kelly): "It was seen running in the background."