Thread overview
Redirect stdout and stderr.
Jul 03, 2012
Tobias Pankrath
Jul 03, 2012
Tobias Pankrath
Jul 03, 2012
Artur Skawina
Jul 03, 2012
Tobias Pankrath
Jul 03, 2012
Wouter Verhelst
July 03, 2012
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!
July 03, 2012
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.
July 03, 2012
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
July 03, 2012
"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
July 03, 2012
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;