将输出重定向到 Cygwin 下的文件时,TCL 脚本行为不同的原因是什么?
当
tclsh ./TestDriver.tcl TestList
tcl 脚本在一行(?)行后停止时调用脚本时。但是,当调用输出重定向到文件时,
tclsh ./TestDriver.tcl TestList >bar.out
它运行顺利。 有什么想法可能导致这种行为的原因吗?
When calling script as
tclsh ./TestDriver.tcl TestList
the tcl script stops after one (?) line. But when called with output redirected to a file
tclsh ./TestDriver.tcl TestList >bar.out
it runs smoothly.
Any ideas what might be the cause of such behavior ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当输出定向到终端或文件时,几乎所有 Tcl 脚本的工作方式都是相同的。虽然有一个
tcl_interactive
变量表明事情可以被关闭,当您提供脚本作为参数时它不会发挥作用。另一个基线差异是stdout
将具有不同的 缓冲;您可以将其更改为:但是,我希望其中的差异会使事情(非常轻微)在重定向到文件的情况下不太可能起作用。无论发生什么(我敢打赌,要么涉及运行子进程,要么使用扩展包),我无法根据提供的证据猜测它。
Almost all Tcl scripts work identically when their output is directed to a terminal or to a file. While there is a
tcl_interactive
variable that things could be keyed off, it doesn't come into play when you're supplying the script as an argument. The other base-line difference is thatstdout
will have different buffering by default; you can change that to be defined with:However, I would expect the differences there to make things (very marginally) less likely to work in the case of being redirected to a file. Whatever is going on (and I bet it either involves running subprocesses or the use of extension packages) I can't guess it on the basis of the evidence provided.
我猜想 tcl 程序正在调用 istty 函数,并根据它是否认为正在写入终端来改变它的行为。可能它正在尝试格式化输出,而宽终端导致它失败。
I would guess the tcl program is calling an istty function, and changing it's behavior depending on if it thinks it's writing to terminal. Possibly, it's attempting to format the output, and a wide terminal is causing it to fail.