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

Lars T. Kyllingstad via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 12 23:09:35 PDT 2014


On Tuesday, 12 August 2014 at 07:53:44 UTC, Timothee Cour via 
Digitalmars-d wrote:
> The deprecation message in 2.066(rc): 'Deprecation: function
> std.process.system is deprecated - Please use executeShell 
> instead' is
> often not what user wants.

Wait, what?  The pull request that deprecated system() was only 
merged a few days ago!  How can it already be in a release 
candidate?  I thought that once the beta cycle started only bug 
fixes would be incorporated.  Deprecations are breaking changes!

But anyway, I agree that the deprecation message is somewhat off 
the mark.  The expression that most closely matches system(cmd) 
is wait(spawnShell(cmd)).


> The behavior of the deprecated std.process should most closely 
> be:
>
> int systemNew(in char[] args){
> auto pipes = pipeShell(args, cast(Redirect)0);
> return wait(pipes.pid);
> }
>
> which could be a function in std.process if we deprecate 
> std.process.system
> (possibly with a few extra parameters such as environment etc).

No, there is no point in using pipeShell() if you're not 
redirecting the streams.  Then you should use spawnShell().  
pipeXyz() is just spawnXyz() plus automatic pipe creation.

wait(spawnShell(cmd)) is simple enough that I don't think it 
needs to be a separate function in std.process.


> Indeed, system doesn't capture output (which could potentially 
> require lots
> of memory) [...]

Note that you can set executeShell's maxOutput parameter to zero, 
in which case it will not collect any output and thus not consume 
any memory.  But it still swallows the output, which you are 
right that system() does not.

I will submit a pull request that changes the deprecation 
message.  Thanks for pointing it out!

Lars


More information about the Digitalmars-d mailing list