www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17844] New: std.process.execute should allow not capturing

https://issues.dlang.org/show_bug.cgi?id=17844

          Issue ID: 17844
           Summary: std.process.execute should allow not capturing stderr
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

Currently, std.process.execute returns in its output a mix of the executed
process's stdout and stderr output.

However, capturing stderr is not always desirable. In fact, unless the D
program invoking std.process.execute needs to parse the child process's error
messages, or needs to relay the error output of the child process to the user
(as it would otherwise not be visible), it is not necessary, and potentially
dangerous, as the program might confuse or attempt to parse the program's error
output as its produced output.

Compare this to the common shell pattern of redirecting a program's output to a
file:

$ program > output.txt

In this manner, should the program fail, the command will complete with a
non-zero exit status, and any error messages emitted by the program will be
directly visible to the user.

D's execute behaviour is as follows:

$ program > output.txt 2>&1

This mixes output and error streams. If the invoking program or script is not
careful to check the error code, and attempts to process the program's output
(which now contains error messages mixed in), it can cause such garbage data to
propagate further than desired.

This is especially egregious if the child program writes informational messages
(warnings) to stderr, which do not affect the correctness of the output (on
stdout) or the exit status. In such a case, it becomes impossible to use
std.process.execute correctly. In some circumstances, such messages can be
printed only in some cases (for example, image processing libraries such as gd,
or text encoding conversion libraries such as iconv, will only print warnings
to stderr on malformed data), which may cause bugs in D programs only
discovered in production.

Thus, std.process.execute needs to be changed to allow stderr to be passed to
the invoking D program's stderr, and only capture stdout (probably via a Config
flag).

--
Sep 20 2017