Nп/п : 8 из 100
 От   : Rich                                2:5075/128        28 авг 23 02:01:43
 К    : Helmut Giese                                          28 авг 23 05:03:02
 Тема : Re: How to use `dup` from TclX
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> ee578df4
@REPLY: <cbhnei1nu5kfqveh27f4m48r61c8h8cudp@4ax.com>
c90e4119
@REPLYADDR Rich <rich@example.invalid>
@REPLYTO 2:5075/128 Rich
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References:
<cbhnei1nu5kfqveh27f4m48r61c8h8cudp@4ax.com>
@TZUTC: -0000
@PID: tin/2.6.1-20211226 ("Convalmore")
(Linux/5.15.117 (x86_64))
@TID: FIDOGATE-5.12-ge4e8b94
Helmut Giese <hgiese@ratiosoft.com> wrote:
> Hello out there,
> But the data is generated by using `puts` so I would need a way to
> redirect `puts` to `stdout`.

puts already outputs to stdout by default -- I think you meant 
"redirect stdout into a file".

> 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.

> proc dumpTree {data} {
>     puts $data
> }

One suggestion for an alternative.  Assuming you can modify the code, 
write your `dumpTree` this way:

proc dumpTree {data {fd stdout}} {
  puts $fd $data
}

When you want the data to go to stdout, call it as:

  dumptree $data

When you want to dump to a file:

  set fd [open dump.txt {WRONLY CREAT TRUNC}]
  dumptree $data $fd
  close $fd

> The file `dump.txt` is generated but it is empty. Moreover running
> this programm repeatedly produces the error
>          error deleting "dump.txt": permission denied

Is the same user running it each time?  This looks to be an OS 
permissions issue that may have nothing to do with Tcl itself.

--- tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.117 (x86_64))
 * 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



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх