The new std.process is ready for review

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 26 08:45:05 PST 2013


On Tue, 26 Feb 2013 11:09:48 -0500, Lars T. Kyllingstad  
<public at kyllingen.net> wrote:

> On Tuesday, 26 February 2013 at 14:22:08 UTC, Steven Schveighoffer wrote:
>> On Sat, 23 Feb 2013 06:31:19 -0500, Lars T. Kyllingstad  
>> <public at kyllingen.net> wrote:
>>
>>> It's been years in the coming, but we finally got it done. :)  The  
>>> upshot is that the module has actually seen active use over those  
>>> years, both by yours truly and others, so hopefully the worst wrinkles  
>>> are already ironed out.
>>>
>>> Pull request:
>>> https://github.com/D-Programming-Language/phobos/pull/1151
>>>
>>> Code:
>>> https://github.com/kyllingstad/phobos/blob/std-process2/std/process2.d
>>>
>>> Documentation:
>>> http://www.kyllingen.net/code/std-process2/phobos-prerelease/std_process2.html
>>>
>>> I hope we can get it reviewed in time for the next release.  (The wiki  
>>> page indicates that both std.benchmark and std.uni are currently being  
>>> reviewed, but I fail to find any "official" review threads on the  
>>> forum.  Is the wiki just out of date?)
>>
>> I just reread the docs, considering Vladimir's point about  
>> space-containing no-arg programs.  I agree there is a problem.
>>
>> We need to not get rid of the single program version of spawn, we need  
>> to simply interpret it as a no-arg program.
>>
>> To have this not work:
>>
>> spawnProcess("c:/Program Files/xyz/xyz.exe");
>>
>> and require this instead:
>>
>> spawnProcess("c:/Program Files/xyz/xyz.exe", []);
>>
>> is not very intuitive.
>>
>> It reminds me of when we had writefln and not writeln, in order to  
>> print out a string with % in it, you had to do writefln("%s", "%s");
>>
>> Now, I think we have an additional issue in that it's difficult to take  
>> a string argument with parameters in it, and pass it in one line:
>>
>> string executeThis = "prog arg1 arg2";
>> auto params = split(executeThis);
>> spawnProcess(params[0], params[1..$]);
>>
>> It would be nice to just be able to do this:
>>
>> spawnProcess(split(executeThis));
>>
>> I think we need an overload for that, especially if we get rid of the  
>> auto-splitting of commands.  It should assert if the array is empty.
>
> I propose we only have two versions:
>
> spawnProcess(string[] args, File stdin, etc...)
> spawnProcess(string[] args, string[string] env, File stdin, etc...)
>
> You'd use it like this:
>
> spawnProcess(["prog"]);

That allocates.  I don't like that requirement.  At the very least there  
should be version which takes a simple string, an easy thing to wrap:

auto spawnProcess(string program, File stdin, etc...)
{
    return spawnProcess((&program)[0..1], stdin, etc...);
}

We should also consider a variadic solution.  In tango, things were done  
with an object, so the arguments were set via one method/constructor, and  
the options (stdin, stdout, etc) were set via another.  This allowed the  
great API of

setArgs(string[] ...)

Which supports

setArgs("progname", "arg1", "arg2")

and

setArgs("progname arg1 arg2".split())

without extra allocation.  However, we have two conflicting parts to  
spawnProcess that would be optional -- the variadic arg list, and the  
optional redirected handles and configuration.

We could just go full-bore variadic...

-Steve


More information about the Digitalmars-d mailing list