capture stdout or stderr

Emil via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 2 14:48:30 PST 2017


On Wednesday, 1 February 2017 at 14:38:18 UTC, angel wrote:
> On Wednesday, 1 February 2017 at 01:08:19 UTC, Emil wrote:
>> is it possible to intercept the  STDOUT or STDERR and capture 
>> the output into a variable ?
.....
>> writeln(output_buffer); # prints '["test 1","test 2"]'
>
> No.
> Please keep in mind, that in Linux, for example, stdout is a 
> file ...
> writeln() interacts with OS API, which, of course, has nothing 
> to do with internal data structures of your application.
> What you could probably do is replace writeln() with a custom 
> logger. In your logger implementation you can add such 
> functionality.

Thank you.



More information about the Digitalmars-d-learn mailing list