Writing to two files at once

wobbles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 13:56:43 PDT 2015


On Thursday, 21 May 2015 at 20:15:29 UTC, wobbles wrote:
> On Thursday, 21 May 2015 at 20:06:08 UTC, wobbles wrote:
>> I would like to write to two files at once.
>>
>> If user specifies verbose flag, output should write to both 
>> stdout and the programs standard output file.
>>
>> Any ideas?
>
> I should add, I'm using a library that already writes it's 
> output to a std.stdout.File that I can provide it, so my 
> thinking is I need a std.stdout.File that points at both stdout 
> and some arbitrary file location.
>
> Tricky I think...

What I ended up doing was creating an OutputRange that contains 
the files I want to write to.
On OutputRange.put I simply print to print to all the files.

Means I had to edit the underlying library, but that's OK as I 
own it, and this seems more robust anyway :)


More information about the Digitalmars-d-learn mailing list