This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Fork and read my child's output


Even in perl, you can do this by opening a pipe.  Here's a sample (in perl -
I don't think I can do it in guile)

(from an email app I wrote) 

pipe(FD_MESSAGE, MESSAGE);
pipe(FD_ENVELOPE, ENVELOPE);

$pid = fork();
if($pid == 0) {
  close(STDIN);
  open(STDIN, "<&FD_MESSAGE") || die;
  close(STDOUT);
  open(STDOUT, "<&FD_ENVELOPE") || die;
  close(FD_ENVELOPE);
  exec(@exec_cmdline);
} elsif ($pid < 0) {
  die("Couldn't fork!\n");
}

If I remember correctly, the child's fd 0 is writeable by the parent, and so
is 1 (I needed this for qmail).  You can probably apply the same thing in
any language that has pipe and dup, or a functional equivelant.  You should
be able to reverse it so the parent reads from the child's stdout instead of
making it writeable.

-Peter

On Tue, Jun 20, 2000 at 06:44:49PM -0700, Andrew Ho wrote:
> Hello,
> 
> I want a Guile script to execute an external program, and collect its
> output, but not to use the shell at all for security and efficiency
> purposes.
> 
> The standard idiom for doing this in Perl is with a special form of open()
> which forks and then connects a filehandle with the child process stdout,
> instead of with a regular file or pipe. Then it is possible to use exec()
> and bypass the shell altogether.
> 
> So I want to do something similar in Guile. fork(), then in the child
> process, sanitize environment and exec(). In the parent process, read the
> child process stdout stream and process it. Just like open-input-pipe, but
> safe from shell escapes.
> 
> Any help would be appreciated.
> 
> Humbly,
> 
> Andrew
> 
> ----------------------------------------------------------------------
> Andrew Ho               http://www.tellme.com/       andrew@tellme.com
> Engineer                   info@tellme.com          Voice 650-930-9062
> Tellme Networks, Inc.                                 Fax 650-930-9101
> ----------------------------------------------------------------------
> 

-- 
The 5 year plan:
In five years we'll make up another plan.
Or just re-use this one.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]