Skip to content

Commit

Permalink
Merge pull request #5742 from CyberShadow/pull-20170920-102045
Browse files Browse the repository at this point in the history
Fix Issue 17844 - std.process.execute should allow not capturing stderr
merged-on-behalf-of: Steven Schveighoffer <schveiguy@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Sep 22, 2017
2 parents efae085 + 71adbee commit 5b5bc61
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion std/process.d
Original file line number Diff line number Diff line change
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 5b5bc61

Please sign in to comment.