从 TCL 输出变量到文本文件

output variables from TCL to a text file

现在我的 TCL 脚本中有三个字符串变量。 Var1 Var2 和 Var3。

我想将它们附加到 output.txt 的末尾,它们之间留有空白 space。

所以添加的行应该是这样的:

Var1 Var2 Var3

你会 open the file in append mode. Then, write the string to the opened channel. You'll probably want the string to be a double-quoted string so variables can be substituted. Then, close 文件。

set fp [open output.txt a]
puts $fp "${Var1} ${Var2} ${var3}"
close $fp