为什么文件名没有被正确呈现 [英] Why filename is not getting rendered properly
问题描述
我需要将程序的输出重定向到一个文件,下面是我用来创建输出日志文件名的代码:
I am in need to redirect output of program to a file and below is the code that I am using to create the output log file name:
set filename "C:\tools\tcl\bin\my.log"
puts "The log file $filename"
但这会打印:
The log file C: ools cinmy.log
注意我也可以接收文件名作为脚本的参数:
Note I can also receive the filename as argument to script:
set logfile [lindex $argv 1]
当以 arg 和常量形式接收日志文件时,如何解决这两种情况的问题?
How can I resolve the issue for both case when receive logfile as arg and as constant?
推荐答案
Tcl
会做 反斜杠替换 并且这些替换只会发生在双引号中.如果您需要文字反斜杠,则必须将其转义.当用大括号括起来时,这些替换不会发生.
Tcl
will do backslash substitution and these substitution will happen only with double quotes. If you need a literal backslash, you have to escape it. When enclosed with braces, these substitution will not happen.
因此,您可以将变量定义为
So, you can define your variable as
set filename "C:\\tools\\tcl\\bin\\my.log"
或
set filename {C:\tools\tcl\bin\my.log}
关于命令行参数的东西,不要打扰.Tcl
会处理它.它将按原样从您的终端接收.
About the command line argument stuff, don't bother. Tcl
will take care of it. It will be received as it is from your terminal.
这篇关于为什么文件名没有被正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!