Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 03, 2012 Redirect stdout and stderr. | ||||
---|---|---|---|---|
| ||||
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 Re: Redirect stdout and stderr. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | 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 Re: Redirect stdout and stderr. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | 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 Re: Redirect stdout and stderr. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | "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 Re: Redirect stdout and stderr. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | 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;
|
Copyright © 1999-2021 by the D Language Foundation