Re: Redirection of standard streams
Chris Angelico <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <CAPTjJmoea=RvN4uuR_tK3tuMb7fXNfQQKvXWBT=4foVJ=oFCCA@mail.gmail.com> |
On Mon, May 12, 2014 at 6:35 PM, Per Hedbor () @ Pike (-) importmöte för mailinglistan <[email protected]> wrote: > First: assign() only modifies what the pike object sees as it's > internal fd. > > write() and werror() are however resolved when the master is compiled > to point to specific low-level fd (or, rather, they have their own > Stdio.File instances, and as such are not affected by what happens > with Stdio.std*) (well, you could always use add_constant to change > them for newly compiled code, but it will not change what they point > to for old code). Technically I'm not actually trying to redirect werror, but a warning message from GTK2.PangoTabArray(0,0) - it's printed to stderr, regardless of the Pike functions. So for this to work, I have to mutate FD 2 itself. In Pike 8.0, this works fine; I created a class that wraps up the details, and I simply allocate an instance of it, and when that instance disappears, the redirection is undone. In 7.8, I've managed to get the redirection itself working, just not the unredirection. > It is possible to do an actual dup() in pike 7.8 by digging around in > the internals of Stdio.File: > > Stdio.File new_stdout; > > #if __VERISON__ < 8.0 > new_stdout = Stdio.File(); > new_stdout->assign( Stdio.stdin->_fd->dup() ); > #else > new_stdout = Stdio.stdout.dup(); > #endif > > 8.0 will hopefully soon be the new stable release (and decade now..) > so backporting should not be needed. Eww, I don't like digging in internals like that! But it does seem to work; thanks! I'll deploy that. Of course, ideal would be for there to be a way for GTK2.PangoTabArray objects to be constructed without generating warnings. But in the absence of that, I can at least construct the eight I need without spamming the user with scary text. Thanks for the help! ChrisA