digitalmars.D.learn - stdout redirect
- Andrea Fontana (1/1) Apr 11 2012 How can I redirect stdout / stderr to file (from D not shell)?
- Andrea Fontana (6/7) Apr 11 2012 Self-reply:
- Stefan (5/13) Apr 11 2012 Careful: D strings are not zero-terminated. args[4].toStringz()
- Andrea Fontana (2/19) Apr 12 2012 Good point Stefan!
- Philip Stuckey (5/27) Apr 11 2015 why not:
- FreeSlave (3/7) Apr 12 2015 It just replaces the object, not redirects output. E.g. if you
- Rikki Cattermole (3/10) Apr 12 2015 You will need to use writefln instead of printf. As printf uses the
How can I redirect stdout / stderr to file (from D not shell)?
Apr 11 2012
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
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:Careful: D strings are not zero-terminated. args[4].toStringz() is the safer choice. Cheers, StefanHow 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
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:Good point Stefan!On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana wrote:Careful: D strings are not zero-terminated. args[4].toStringz() is the safer choice. Cheers, StefanHow 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 12 2012
On Thursday, 12 April 2012 at 08:11:58 UTC, Andrea Fontana wrote:On Wednesday, 11 April 2012 at 15:25:56 UTC, Stefan wrote:why not: import std.stdio; stdout = File(args[4], "w+"); stderr = File(args[4], "w+");On Wednesday, 11 April 2012 at 13:00:45 UTC, Andrea Fontana wrote:Good point Stefan!On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana wrote:Careful: D strings are not zero-terminated. args[4].toStringz() is the safer choice. Cheers, StefanHow 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 2015
On Sunday, 12 April 2015 at 04:39:06 UTC, Philip Stuckey wrote:why not: import std.stdio; stdout = File(args[4], "w+"); stderr = File(args[4], "w+");It just replaces the object, not redirects output. E.g. if you use printf somewhere it will use stdout, not file.
Apr 12 2015
On 13/04/2015 1:12 a.m., FreeSlave wrote:On Sunday, 12 April 2015 at 04:39:06 UTC, Philip Stuckey wrote:You will need to use writefln instead of printf. As printf uses the processes stdout. Changing this would be tricky and OS based.why not: import std.stdio; stdout = File(args[4], "w+"); stderr = File(args[4], "w+");It just replaces the object, not redirects output. E.g. if you use printf somewhere it will use stdout, not file.
Apr 12 2015