문제

I would like to write in file like this:

set fh [open $tmpFileName w]
puts $fh "set a [create_object]"
puts $fh "$a proc1_inside_a"
puts $fh "$a proc2_inside_a"
close $fh

But its get the error message, because a variable will be created when tmpFileName file will be executed. So I get the error like this:

can't read "a": no such variable

Can you please help me to resolve this?

도움이 되었습니까?

해결책

You just need to use a different quoting mechanism. Double quotes allow command and variable substitution. Braces will keep their contents verbatim (inhibit substutition)

set fh [open $tmpFileName w]
puts $fh {set a [create_object]}
puts $fh {$a proc1_inside_a}
puts $fh {$a proc2_inside_a}
close $fh

Documentation is available:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top