Controlling stdin and stdouts of other executables

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Tue May 8 09:12:25 AEST 1990


In article <26405616.54D3 at tct.uucp> chip at tct.uucp (Chip Salzenberg) writes:
> According to dkeisen at Gang-of-Four.Stanford.EDU (Dave Eisen):
> >system ("command > /dev/null 2>&1");
> Beware system().
  [ points out security problems ]
> 	sprintf(buf, "/usr/lib/sendmail -oem '%s' <%s", address, tempfile);
> 	system(buf);

system() can be used safely. First, make sure your environment is
controlled. Second, add the address and the temporary file to the
environment. Finally, use

  system("exec /usr/lib/sendmail -oem \"$ADD\" < \"$TEMPFILE\"");

Spawning the process yourself is better, but as Chip points out,
system() is simpler for novices. Caveat: I haven't tested this.

---Dan



More information about the Comp.unix.questions mailing list