Redirection of standard streams
Chris Angelico <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <CAPTjJmrSwNavhPxVcpPL8oBjW765FSsZ-mzoSmeYDyiHbmFTBQ@mail.gmail.com> |
Back when I first met the concept of I/O redirection, the procedure was: 1) Duplicate the current handle 2) Force-duplicate (dup2) the desired handle over the standard stream 3) Do whatever you need with redirection active 4) Force-duplicate the step 1 copy over the standard stream, undoing redirection. I've been trying to do this in Pike, temporarily redirecting stderr to nowhere (hence my previous question about /dev/null vs NUL: across platforms), and have come across a problem: in Pike 7.8, dup() doesn't actually duplicate the file descriptor. Pike v7.8 release 856 running Hilfe v3.5 (Incremental Pike Frontend) > Stdio.stderr->dup(); (1) Result: Stdio.FILE(0, 0, 777 /* fd=2 */) Pike v8.0 release 1 running Hilfe v3.5 (Incremental Pike Frontend) > Stdio.stderr->dup(); (1) Result: Stdio.FILE(0, 0, 777 /* fd=10 */) As a result, I can dup2() to do the redirection, but can't undo that. (Also, I had trouble using the more obvious assign(), but haven't tracked that down.) Is there an alternative way to "really duplicate" an fd in 7.8? Alternatively, can the 8.0 behaviour be backported to 7.8 in time for the next release? ChrisA