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

吃可爱长大的小学妹 提交于 2019-12-23 04:45:14

问题


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

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


回答1:


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



来源:https://stackoverflow.com/questions/5965026/tcl-tk-memchan-fifo-how-to-rename-fifo-as-stdout-in-a-tcl-tk-application-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!