www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Redirect stdout and stderr.

reply "Tobias Pankrath" <tobias pankrath.net> writes:
Is it possible to redirect stdout in a way that all following 
calls to
writeln etc just write to /dev/null or something similar?

Thanks!
Jul 03 2012
next sibling parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Tuesday, 3 July 2012 at 18:30:41 UTC, Tobias Pankrath wrote:
 Is it possible to redirect stdout in a way that all following 
 calls to
 writeln etc just write to /dev/null or something similar?

 Thanks!
And I need to restore them afterwards.
Jul 03 2012
prev sibling next sibling parent reply Artur Skawina <art.08.09 gmail.com> writes:
On 07/03/12 20:30, Tobias Pankrath wrote:
 Is it possible to redirect stdout in a way that all following calls to
 writeln etc just write to /dev/null or something similar?
stdout.open(outfilename, "wt"); artur
Jul 03 2012
parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Tuesday, 3 July 2012 at 18:39:09 UTC, Artur Skawina wrote:
 On 07/03/12 20:30, Tobias Pankrath wrote:
 Is it possible to redirect stdout in a way that all following 
 calls to
 writeln etc just write to /dev/null or something similar?
stdout.open(outfilename, "wt"); artur
Thank you. After a first search, thought I need to use dup2, freopen etc. If someone finds this thread, this is how to restore stdout: Just store it in another variable like this. auto original = stdout; stdout.open(newdest, "wt"); //restore stdout = original;
Jul 03 2012
prev sibling parent Wouter Verhelst <wouter grep.be> writes:
"Tobias Pankrath" <tobias pankrath.net> writes:

 Is it possible to redirect stdout in a way that all following calls to
 writeln etc just write to /dev/null or something similar?
If it's any form of unix, all you need to do is close(1). If you still need the fd afterwards, you want to use dup() first so you can restore them (with dup2()) later. -- The volume of a pizza of thickness a and radius z can be described by the following formula: pi zz a
Jul 03 2012