Xref: utzoo comp.lang.c:20628 comp.unix.wizards:17639
Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!network!ucsd!orion.cf.uci.edu!uci-ics!zardoz!ccicpg!cci632!rit!tropix!moscom!ur-valhalla!uhura.cc.rochester.edu!rochester!rutgers!apple!oliveb!amdahl!dlb!megatest!djones
From: djones@megatest.UUCP (Dave Jones)
Newsgroups: comp.lang.c,comp.unix.wizards
Subject: Re: redirect stdin when using execl
Message-ID: <5725@goofy.megatest.UUCP>
Date: 22 Jul 89 22:21:46 GMT
References: <2489@mit-caf.MIT.EDU>
Organization: Megatest Corporation, San Jose, Ca
Lines: 27

From article <2489@mit-caf.MIT.EDU>, by vlcek@mit-caf.MIT.EDU (Jim Vlcek):
> 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.


Maybe. But that wasn't the question. The question was how to redirect stdin when
using execl, not how to rebind stdin after the execl.

Anyway, using freopen is only possible if you have access to the source code
of all the programs which will be execled, are already responsible for their
content, and can easily modify and dependably distribute the modified version
to all sites which will use the execling program.  It may be much much easier to
redirect it using dup2 on the execling side -- I presume that's what the
various shells do.


             -- Dave