std.process.execute without capturing stderr?

Paul Backus snarwin at gmail.com
Thu Sep 20 07:36:06 UTC 2018


On Thursday, 20 September 2018 at 07:24:52 UTC, berni wrote:
> I need to execute a program and capture stdout, which I hoped 
> std.process.execute would do. But unfortunatly this command 
> also captures stderr, which I need to be ignored. When looking 
> at the implementation of std.process.execute I see, that I can 
> probably do this by removing "Redirect.stderrToStdout" in the 
> function executeImpl. But for that I have to copy lots of 
> functions from phobos in my own code. Is there an easier way to 
> do that?
>
> [...]
>
> Here my complete program:
>
>> import std.process;
>> import std.stdio;
>> import std.array;
>> 
>> int main(string[] args)
>> {
>>     const result = execute(args[1..$]);
>>     writeln(result[1].replace("\\","\\\\").replace(" ","\\s"));
>>     return result[0];
>> }

Looks like `Config.stderrPassThrough` [1] should do what you want:

     const result = execute(args[1..$], null, 
Config.stdErrPassThrough);

[1] 
https://dlang.org/phobos/std_process.html#.Config.stderrPassThrough


More information about the Digitalmars-d-learn mailing list