deprecation message std.process.system=>executeShell often not what's needed

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 12 18:58:03 PDT 2014


On Tue, Aug 12, 2014 at 3:41 PM, Vladimir Panteleev via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Tuesday, 12 August 2014 at 07:53:44 UTC, Timothee Cour via
> Digitalmars-d wrote:
>
>> int systemNew(in char[] args){
>> auto pipes = pipeShell(args, cast(Redirect)0);
>> return wait(pipes.pid);
>> }
>>
>
> Why use pipeShell instead of spawnShell?


spawnShell works too.


> And why `cast(Redirect)0`? It's not necessary.


it is, otherwise it defaults to Redirect.all which has different semantics
than 'system' (so it's not a replacement of it).
Btw, I don't like the cast either; shouldn't there be a 'none=0' value in
the enum?


> Also note that shell commands (incl. system) take one string argument, not
> an array.
>

Please re-read my post carefully. pipeShell indeed takes 'in char[]
command', not string (char array, not string array nor string).


>
> This can be a simpler one-liner: wait(executeShell(cmd))
>

Please re-read my original post more carefully. This is not what 'system'
does. system doesn't redirect stdin/stdout. executeShell on the other hand
does this: "The functions capture what the child process prints to both its
standard output and standard error streams, and return this together with
its exit code".


>
> So, the deprecation message is not far off, perhaps missing a `.wait()`.
>

The deprecation message is indeed wrong. It should be wait(spawnShell(cmd))
instead of executeShell(cmd). Different function and missing wait.


>
>  Indeed, system [..] doesn't wait until completion, unlike executeShell.
>>
>
> You mean it does wait until completion?
>

Bad wording; what I meant is we have to wait until completion to get any
stdout output with executeShell (it returns it) whereas for
system/systemNew/wait(spawnShell) the output is displayed in realtime via
stdout.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140812/fe76f870/attachment-0001.html>


More information about the Digitalmars-d mailing list