guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Support for (system '("echo" "foo" "bar"))


From: Rob Browning
Subject: Re: Support for (system '("echo" "foo" "bar"))
Date: Thu, 30 Oct 2003 23:51:35 -0600
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Kevin Ryde <address@hidden> writes:

> If it does a fork and exec then it could be called fork-exec :).
>
> The old DOS systems used to use "spawn" for that sort of thing I think
> (spawnl, spawnle, etc like the exec functions).
>
> Either way, if it can get the errno back to the parent when exec fails
> (and use _exit) then it'd be a nice improvement over a fork and exec
> one might write explicitly.  (A close-on-exec pipe is a good way to do
> that.)

Right now I just have this first (quick) pass at (system* . args),
which should provide access to errno via scm_execlp:

{
  if (SCM_NULLP (cmds))
    SCM_WRONG_TYPE_ARG (1, cmds);

  if (SCM_CONSP (cmds))
    {
      // better be a list of strings, and we call exec.
      int pid = fork ();
      if (pid == -1)
        SCM_SYSERROR;
      else if (pid)
        {
          int wait_result;
          int status;
          SCM_SYSCALL (wait_result = waitpid (pid, &status, 0));
          if (wait_result == -1) SCM_SYSERROR;
          return SCM_MAKINUM (0L + status);
        }
      else
        {
          scm_execlp (SCM_CAR(cmds), cmds);
          SCM_SYSERROR;
          /* not reached.  */
          return SCM_BOOL_F;
        }
    }
  else
    SCM_WRONG_TYPE_ARG (1, SCM_CAR (cmds));
}


-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]