Re: Writing to two files at once
On Thursday, 21 May 2015 at 21:02:42 UTC, Ali Çehreli wrote: On 05/21/2015 01:56 PM, wobbles wrote: 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. Just like MultiFile example here: :) http://ddili.org/ders/d.en/ranges.html#ix_ranges.OutputRange Ali Yeah! This is my implementation: public struct OutputSink{ File[] files; @property void addFile(File f){ files ~= f; } @property File[] file(){ return files; } void put(Args...)(string fmt, Args args){ foreach(file; files) file.writefln(fmt, args); } } I'll remember to look in your book next time I need something simple :)
Re: Writing to two files at once
On Thursday, 21 May 2015 at 21:16:59 UTC, wobbles wrote: On Thursday, 21 May 2015 at 21:00:15 UTC, Cassio Butrico wrote: If I understand right you want to redirect the output to a file by a flag , another file type , video printer is it? I think by video printer you mean the console? If so, yes. I believe I've solved it anyway, see Ali and my answer above. Thanks! You're right, Ali 's book is of great help for all
Re: Writing to two files at once
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... If it is hardcoded to take a File (I.e. it's not a template parameter), then your options are: modify the library, modify phobos or use the OS to do the duplication. On *nix you should be able to do it quite easily, don't know about windows.
Re: Writing to two files at once
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 :)
Re: Writing to two files at once
If I understand right you want to redirect the output to a file by a flag , another file type , video printer is it?
Re: Writing to two files at once
On 05/21/2015 01:56 PM, wobbles wrote: 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. Just like MultiFile example here: :) http://ddili.org/ders/d.en/ranges.html#ix_ranges.OutputRange Ali
Re: Writing to two files at once
On Thursday, 21 May 2015 at 21:00:15 UTC, Cassio Butrico wrote: If I understand right you want to redirect the output to a file by a flag , another file type , video printer is it? I think by video printer you mean the console? If so, yes. I believe I've solved it anyway, see Ali and my answer above. Thanks!
Writing to two files at once
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?
Re: Writing to two files at once
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...