----------------------------------------------------------------------------------
@MSGID: <slrnueplmm.6epk.avl@logic.at> 36bde820
@REPLY: 1@dont-email.me> ee578df4
@REPLYADDR Andreas Leitgeb <avl@logic.at>
@REPLYTO 2:5075/128 Andreas Leitgeb
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <slrnueplmm.6epk.avl@logic.at>
@RFC-References:
<cbhnei1nu5kfqveh27f4m48r61c8h8cudp@4ax.com> 1@dont-email.me>
@RFC-Reply-To: avl@logic.at
@TZUTC: -0000
@PID: slrn/1.0.3 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
Rich <
rich@example.invalid> wrote:
> Helmut Giese <
hgiese@ratiosoft.com> wrote:
>> I found `dup` from TclX but apparently I cannot use it correctly.
>> Here is my (compressed) attempt:
> From what I read in the tclx manpage, your code looks to be using the
> dup call correctly.
I`d probably first dup the original stdout to a new filehandle (one-arg
variant of dup returns new filehandle), then dup the file onto stdout,
and finally (after "dumptree") dup the previously created filehandle
back to stdout.
set dfd [open $dumpfile w]
set origout [dup stdout]; # make backup of application`s stdout
dup $fdf stdout
dumptree "Hello World!"
close stdout; close $dfd ;# I think you need to close both!
dup $origout stdout
close $origout ;# close the backup-fd of stout. no need to keep them both
try that - I think your symptom could be caused by not closing
both filedescriptors to the file (namely both stdout and the one
originally returned from open)
Whether you actually need to backup and restore the original stdout
is your decision: does your script ever need to output something to
stdout after the call to "dumptree" ?
PS: another maybe-caveat: if the application is on Windows and
actually opening a window (using Tk, or maybe even just tclsh`s
"console") then all the stdout-handling might be just screwed,
so that even redirecting a file-fd to stdout might just not work.
I don`t have any experience with Tclx on Windows.
--- slrn/1.0.3 (Linux)
* Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441