Xref: utzoo comp.lang.c:20293 comp.unix.wizards:17442 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!gatech!udel!rochester!rit!tropix!moscom!ur-valhalla!uhura.cc.rochester.edu!sunybcs!rutgers!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!mirror!frog!john From: john@frog.UUCP (John Woods) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: redirect stdin when using execl Keywords: execl redirect stdin < Message-ID: <1520@frog.UUCP> Date: 22 Jul 89 01:39:00 GMT References: <414@sc50.UUCP> <851@pcsbst.UUCP> Followup-To: comp.lang.c Organization: Misanthropes-R-Us Lines: 37 In article <851@pcsbst.UUCP>, torsten@pcsbst.UUCP (torsten) writes: > In article <414@sc50.UUCP> ron@sc50.UUCP ( Ron Winnacott ) writes: > >Hello net. > >execl("/bin/mail","mail","ron","<","/tmp/tfile",NULL); > I think this should do it: > execl("/bin/sh","sh","/bin/mail ron < /tmp/tfile",NULL); Or, you might try something general-purpose like: fexecve(sin, sout, serr, av, ev) int sin, sout, serr; char **av, *ev; { dup2(sin, 0); /* note: dup2(0, 0) is a no-op */ dup2(sout, 1); dup2(serr, 2); if (sin > 2) close(sin); /* delete extra file handles */ if (sout > 2) close(sout); if (serr > 2) close(serr); return execve(av, ev); } Two provisos: System V users will want to use fcntl(, F_DUPFD, ) instead of dup2() (and note that it is a little tricky to do that correctly), and this doesn't quite work if you do silly things like fexecve(1, 2, 0, argvec, envp); though it can be made to work if need be. (Left to the student as an exercise :-) -- John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101 ...!decvax!frog!john, john@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu People...How you gonna FIGURE 'em? Don't bother, S.L.--Just stand back and enjoy the EVOLUTIONARY PROCESS...