开发者

Tcl/Tk - Memchan - fifo - how to rename fifo as stdout in a tcl/tk application which has Memchan statically linked?

开发者 https://www.devze.com 2023-03-05 07:32 出处:网络
I cross posted this question on comp.lang.tcl. I am developing a Tcl/Tk application (call it rs) and I want to redirect stdout and stderr to a text box in my Tcl/Tk application. I am using Memchan to

I cross posted this question on comp.lang.tcl.

I am developing a Tcl/Tk application (call it rs) and I want to redirect stdout and stderr to a text box in my Tcl/Tk application. I am using Memchan to achieve this (I statically linked Memchan into my application). But I am unable to rename the fifo channel I created as stderr. (The same thing holds true for stdout too)

For example, in the following snippet, I am closing stderr and then opening fifo as stderr but fifo channel remains named as fifo0 not as stderr.

 $ rs
 rs> package require Memchan
 2.3
 rs> chan names
 stdin stdout stderr
 rs> close stderr
 rs> chan names
 stdin stdout
 rs> set stderr [fifo]
 fifo0
 rs> chan names
 fifo0 stdin stdout

I expected stderr instead of fifo0 when I typed in the last of the chan names command.

But when I use tclsh8.5 the above sequence produces the desired effect i.e fifo is renamed as stderr

 $ tclsh8.5
 % package req Memchan
 2.3
 % chan names
 stdin stdout stderr
 % close stderr
 % chan names
 stdin stdout
 % set stderr [fifo]
 fifo0
 % chan names
 stderr stdin stdout

Note: no fifo0 but we get the des开发者_运维知识库ired stderr.

Can someone point out how to reproduce the behavior in tclsh8.5 in my Tcl/Tk application rs.


Since memchan doesn't produce channels backed up by a file descriptor, it can't replace the standard channels (which always correspond to FDs 0, 1 and 2).

0

精彩评论

暂无评论...
验证码 换一张
取 消