www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - stdout redirect

reply "Andrea Fontana" <nospam example.com> writes:
How can I redirect stdout / stderr to file (from D not shell)?
Apr 11 2012
next sibling parent "Andrea Fontana" <nospam example.com> writes:
On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana wrote:
 How can I redirect stdout / stderr to file (from D not shell)?

Self-reply: It works using std.c way: import std.cstream; std.c.stdio.freopen(args[4].ptr, "w+", dout.file); std.c.stdio.freopen(args[4].ptr, "w+", derr.file);
Apr 11 2012
prev sibling next sibling parent "Stefan" <stefan schuerger.com> writes:
On Wednesday, 11 April 2012 at 13:00:45 UTC, Andrea Fontana wrote:
 On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana 
 wrote:
 How can I redirect stdout / stderr to file (from D not shell)?

Self-reply: It works using std.c way: import std.cstream; std.c.stdio.freopen(args[4].ptr, "w+", dout.file); std.c.stdio.freopen(args[4].ptr, "w+", derr.file);

Careful: D strings are not zero-terminated. args[4].toStringz() is the safer choice. Cheers, Stefan
Apr 11 2012
prev sibling parent "Andrea Fontana" <nospam example.com> writes:
On Wednesday, 11 April 2012 at 15:25:56 UTC, Stefan wrote:
 On Wednesday, 11 April 2012 at 13:00:45 UTC, Andrea Fontana 
 wrote:
 On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana 
 wrote:
 How can I redirect stdout / stderr to file (from D not shell)?

Self-reply: It works using std.c way: import std.cstream; std.c.stdio.freopen(args[4].ptr, "w+", dout.file); std.c.stdio.freopen(args[4].ptr, "w+", derr.file);

Careful: D strings are not zero-terminated. args[4].toStringz() is the safer choice. Cheers, Stefan

Good point Stefan!
Apr 12 2012