[phobos] Major improvements to std.process

Lars Tandle Kyllingstad lars at kyllingen.net
Fri Mar 12 07:20:09 PST 2010


I've committed a new version with the following changes:
  - Removed ChildTerminatedException, made wait() return -signal.
  - Added GUI flag which does nothing on POSIX.


Steve Schveighoffer wrote:
> [...]
> 
> It's just that the creation of the pipes and creation of the process always go hand in hand, you very seldom want to separate those functions.  It's somewhat of a nuisance to write many times "create this pipe, now this one, then create the process that uses them".  It would be much nicer to just say "create the process, use pipes for these handles, and give me everything back when you're done."  I liken it to how constructors unify the process of creation and initialization in one line.  Yes, you can split them, but why?
> 
> I'm not saying there isn't use for your signatures, I agree having fine-grained control over which file descriptors are used is a good thing.  I just think we should cater to common cases, even if it's via wrapper functions/structs.

Ok.  I agree there should be a set of convenience functions to take care 
of the most common tasks.  Here's a suggestion:

   struct ProcessPipes
   {
       Pid pid;
       File stdin, stdout, stderr;
   }

   // Spawn process with redirected input/output, return immediately.
   // Our version of popen().
   ProcessPipes pipeProcess(string command, RedirectFlags flags);
   ProcessPipes pipeShell(string command, RedirectFlags flags);

   // Spawn process, optionally capture output, wait for it to finish,
   // return exit code.
   int execute(string command)
   int execute(string command, out string output);

   // Run command in shell, optionally capture output, wait for
   // it to finish, return exit code.  (Already implemented.)
   int shell(string command);
   int shell(string command, out string output);

-Lars


More information about the phobos mailing list