Skip to content

Commit

Permalink
Fix Issue 17844 - std.process.execute should allow not capturing stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Sep 21, 2017
1 parent efae085 commit 71adbee
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion std/process.d
Expand Up @@ -1430,6 +1430,19 @@ enum Config
Calling $(LREF wait) or $(LREF kill) with the resulting $(D Pid) is invalid.
*/
detached = 64,

/**
By default, the $(LREF execute) and $(LREF executeShell) functions
will capture child processes' both stdout and stderr. This can be
undesirable if the standard output is to be processed or otherwise
used by the invoking program, as `execute`'s result would then
contain a mix of output and warning/error messages.
Specify this flag when calling `execute` or `executeShell` to
cause invoked processes' stderr stream to be sent to $(REF stderr,
std,stdio), and only capture and return standard output.
*/
stderrPassThrough = 128,
}


Expand Down Expand Up @@ -2484,7 +2497,11 @@ private auto executeImpl(alias pipeFunc, Cmd, ExtraPipeFuncArgs...)(
import std.array : appender;
import std.typecons : Tuple;

auto p = pipeFunc(commandLine, Redirect.stdout | Redirect.stderrToStdout,
auto redirect = (config & Config.stderrPassThrough)
? Redirect.stdout
: Redirect.stdout | Redirect.stderrToStdout;

auto p = pipeFunc(commandLine, redirect,
env, config, workDir, extraArgs);

auto a = appender!(ubyte[])();
Expand Down Expand Up @@ -2546,6 +2563,10 @@ private auto executeImpl(alias pipeFunc, Cmd, ExtraPipeFuncArgs...)(
auto r3 = executeShell("exit 123");
assert(r3.status == 123);
assert(r3.output.empty);
auto r4 = executeShell("echo stderr test, please ignore 1>&2",
null, Config.stderrPassThrough);
assert(r4.status == 0);
assert(r4.output.empty);
}

@safe unittest
Expand Down

0 comments on commit 71adbee

Please sign in to comment.