Xref: utzoo comp.lang.c:19282 comp.unix.wizards:16878 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!mit-amt!mit-caf!vlcek From: vlcek@mit-caf.MIT.EDU (Jim Vlcek) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: redirect stdin when using execl Message-ID: <2489@mit-caf.MIT.EDU> Date: 11 Jun 89 03:48:31 GMT References: <851@pcsbst.UUCP> <5587@goofy.megatest.UUCP> Reply-To: vlcek@mit-caf.UUCP (Jim Vlcek) Organization: Microsystems Technology Laboratories, MIT Lines: 22 In article <5587@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: >> In article <414@sc50.UUCP> ron@sc50.UUCP ( Ron Winnacott ) writes: >>>Can anyone tell me how to redirect stdin when I use execl to >>>start a new program. > >Under BSD Unix, you use dup2. plus a bit of code showing how to fork(), dup2(), and then execl() to get the desired effect. I think a much better way, under BSD, is to use freopen() to attach stdin to the redirected file. Such redirection is, in fact, precisely the intended usage of this function call. Is freopen() a Berklism, or do you have that in Sys V as well? I'm almost completely unfamiliar with the latter. The original example, passing the string "<" and the redirected file, was so innocently misguided I really got a laugh out of it. execl()'ing "/bin/sh" to parse the command, or using system(), on the other hand, were somewhat less amusing. Jim Vlcek (vlcek@caf.mit.edu uunet!mit-caf!vlcek)