[phobos] Major improvements to std.process

Steve Schveighoffer schveiguy at yahoo.com
Thu Mar 11 06:19:28 PST 2010


This looks great!

Where would the Windows gui flag fit in?

Also, note that one can redirect both stdout and stderr to the same File, which means if you are closing both, you should only call close once on those files (I'm not sure how bad it is, but it probably will result in an ignored error from the OS).

Another thing, I liked how the pid struct used to contain the pipes when I wanted to control the std handles, and how the spawnProcess function handled the pipe creation for me.  I wonder if it's possible to pass in a default argument for the handles, or have a separate function that does the pipe creation, and store the right ends of the pipe in the returned struct.

For example, if I want control over all three handles, I have to do:

auto lsstdin = Pipe.create();
auto lsstdout = Pipe.create();
auto lsstderr = Pipe.create();

auto lspid = spawnProcess("ls -l", lsstdin.readEnd, lsstdout.writeEnd, lsstderr.writeEnd);

If I do that a lot, I have a lot of pipes littering my local variables, and the code is very verbose.

I think we can build this on top of your function, into a struct/class that handles this stuff for you.  Or we could make the spawnProcess arguments variadic and put the created pipe handles back in the pid struct.

-Steve


----- Original Message ----
> From: Lars Tandle Kyllingstad <lars at kyllingen.net>
> To: Phobos mailing list <phobos at puremagic.com>
> Sent: Thu, March 11, 2010 6:33:29 AM
> Subject: [phobos] Major improvements to std.process
> 
> I have just redone the interface of my std.process proposal, and I am very 
> pleased with the result.
> 
> Calling "ls -l" is now as simple as writing
> 
>    spawnProcess("ls -l");
> 
> while "ls -l | grep foobar > filesNamedFoobar.txt" isn't that big of a deal 
> either:
> 
>     auto pipe = Pipe.create();
>     auto file = File("filesNamedFoobar.txt", "w");
> 
>     auto lsPid = spawnProcess("ls -l", stdin, pipe.writeEnd);
>     scope(exit) lsPid.wait();
> 
>     auto grPid = spawnProcess("grep foobar", pipe.readEnd, file);
>     scope(exit) grPid.wait();
> 
> The documentation is also a lot better now (though the spawnProcess() signature 
> looks horrible, but that's a DDoc issue).  As always, please check out
> 
>     http://github.com/kyllingstad/ltk/blob/master/ltk/process.d
>     http://kyllingen.net/code/ltk/doc/process.html
> 
> and give me your opinions.
> 
> -Lars
> 
> 
> -- Lars Tandle Kyllingstad
> @: lars at kyllingen.net
> #: 40233221
> w: http://www.kyllingen.net
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos



      


More information about the phobos mailing list