原创 TCL Puts命令

2012-12-3 12:14 4972 19 15 分类: MCU/ 嵌入式 文集: TCL/TK

NAMENAME

puts -
Write to a channel

SYNOPSISSYNOPSIS

puts ?-nonewline? ?channelId? string

DESCRIPTIONDESCRIPTION

Writes the characters given by string to the channel given by channelId.

ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdout or stderr), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension. The channel must have been opened for output.

If no channelId is specified then it defaults to stdout. Puts normally outputs a newline character after string, but this feature may be suppressed by specifying the -nonewline switch.

Newline characters in the output are translated by puts to platform-specific end-of-line sequences according to the current value of the -translation option for the channel (for example, on PCs newlines are normally replaced with carriage-return-linefeed sequences. See the fconfigure manual entry for a discussion on ways in which fconfigure will alter output.

Tcl buffers output internally, so characters written with puts may not appear immediately on the output file or device; Tcl will normally delay output until the buffer is full or the channel is closed. You can force output to appear immediately with the flush command.

When the output buffer fills up, the puts command will normally block until all the buffered data has been accepted for output by the operating system. If channelId is in nonblocking mode then the puts command will not block even if the operating system cannot accept the data. Instead, Tcl continues to buffer the data and writes it in the background as fast as the underlying file or device can accept it. The application must use the Tcl event loop for nonblocking output to work; otherwise Tcl never finds out that the file or device is ready for more output data. It is possible for an arbitrarily large amount of data to be buffered for a channel in nonblocking mode, which could consume a large amount of memory. To avoid wasting memory, nonblocking I/O should normally be used in an event-driven fashion with the fileevent command (do not invoke puts unless you have recently been notified via a file event that the channel is ready for more output data).

tcl
PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

coyoo 2012-5-3 11:18

puts命令在往文件里写入数据时,一般先会写入buffer里,这里的buffer就是pc的内存,只有当buffer满了以后才统一转移到文件中,所以这样一来带来了2个问题:一个问题是占用一定的内存,另一个问题是写入的数据没有立即出现在目标文件中。这个时候可以使用flush命令来使数据立即写入到文件中。当然还有在使用命令的时候指定使用阻塞或者非阻塞模式来解决这个问题。
相关推荐阅读
coyoo 2025-01-16 13:07
PET探测器
记录下PET探测器的知识点。所谓探测器,即探测出核医学里的核辐射。人体代谢等反应发生的湮没产生了伽马光子,该伽马光子的能量很强,当前很难直接探测(尽管还存在直接探测的探测器)。所以,更多的时候是间接探...
coyoo 2024-12-25 14:13
ALTERA Cyclone 10器件的使用-8:特定的上电顺序
概述 Intel 要求用户为其10代FPGA器件使用特定的上电和掉电顺序,这就要求用户在进行FPGA硬件设计的时候必须选择恰当的FPGA供电方案,并合理控制完整的供电上电顺序。经过在Cyclone 1...
coyoo 2024-12-22 11:46
AD9218子板在新处理板上表现的问题
概述 新的数据处理板融合了数字和数据处理功能模块,计划采用ADI的4通道串行ADC芯片代替之前的并行ADC。由于初次使用,所以初次设计时预留了AD9218的子板的插槽。 在调试AD9633功能的同时并...
coyoo 2024-12-14 17:15
在Cyclone 10 GX器件上实现高精度TDC探索
概述 Cyclone 10 GX器件的ALM结构与Cyclone V类似,所以在Cyclone 10 GX器件上实现TDC功能理论上是可以完全参考甚至移植自Cyclone V系列的成功案例。但是,现实...
coyoo 2024-12-10 13:28
Cyclone V GX FPGA设计TDC的优化问题
概述 通过前面的研究学习,已经可以在CycloneVGX器件中成功实现完整的TDC(或者说完整的TDL,即延时线),测试结果也比较满足,解决了超大BIN尺寸以及大量0尺寸BIN的问题,但是还是存在一些...
coyoo 2024-12-03 12:20
比较器检测模拟脉冲说明(四)
概述 说明(三)探讨的是比较器一般带有滞回(Hysteresis)功能,为了解决输入信号转换速率不够的问题。前文还提到,即便使能滞回(Hysteresis)功能,还是无法解决SiPM读出测试系统需要解...
我要评论
1
19
关闭 站长推荐上一条 /3 下一条