Re: stdout redirect

2015-04-12 Thread Rikki Cattermole via Digitalmars-d-learn

On 13/04/2015 1:12 a.m., FreeSlave wrote:

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.


You will need to use writefln instead of printf. As printf uses the 
processes stdout. Changing this would be tricky and OS based.


Re: stdout redirect

2015-04-12 Thread FreeSlave via Digitalmars-d-learn

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.


Re: stdout redirect

2015-04-11 Thread Philip Stuckey via Digitalmars-d-learn

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:
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!


why not:
import std.stdio;
stdout = File(args[4], w+);
stderr = File(args[4], w+);



Re: stdout redirect

2012-04-12 Thread Andrea Fontana

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!



stdout redirect

2012-04-11 Thread Andrea Fontana

How can I redirect stdout / stderr to file (from D not shell)?


Re: stdout redirect

2012-04-11 Thread Andrea Fontana

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);




Re: stdout redirect

2012-04-11 Thread Stefan

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