Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ark1!dpaulso From: dpaulso@relay.nswc.navy.mil (Dave Paulson) Newsgroups: comp.unix.questions Subject: "temporarily" redirecting stdin Keywords: redirect, stdin Message-ID: <1989Dec14.185745.7465@relay.nswc.navy.mil> Date: 14 Dec 89 18:57:45 GMT Reply-To: dpaulso@ark1.nswc.navy.mil (Dave Paulson) Distribution: usa Organization: Naval Surface Warfare Center, Dahlgren, VA Lines: 22 i have a program which wants to initialize itself by reading in a configuration file. a lex/yacc scanner/parser pair will handle the reading of the config file. now, the scanner that lex generates gathers its tokens from stdin (a behavior i want to retain), but i'll need to use stdin for my own purposes after the initialization is complete. what i propose to do is summarized in the following pseudocode: stdin_save = dup(fileno(stdin)); /* stdin_save is an int */ freopen("config.file","r",stdin); /* connect stdin to the config file*/ yyparse(); /* works ok, input comes from file */ close(fileno(stdin)); /* free stdin descriptor */ dup(stdin_save); /* restore old stdin */ this doesn't work. after the second dup(), reading stdin results in EOF. what have i overlooked? -- Dave Paulson Synetics / Naval Surface Warfare Center dpaulso@relay.nswc.navy.mil voice: (703) 663-2137