开发者

Input from keyboard in Tcl

开发者 https://www.devze.com 2022-12-13 00:40 出处:网络
How do I give input to a Tcl s开发者_高级运维cript through the keyboard? Is there any thing like scanf() in C?The gets command is probably what you want.

How do I give input to a Tcl s开发者_高级运维cript through the keyboard? Is there any thing like scanf() in C?


The gets command is probably what you want.

set data [gets stdin]
# or
set numchars [gets stdin data]

The scan command can be used to parse the input similar to how scanf does with C. It uses the format: scan string format ?varName varName ...?

Thus, to parse an input like "5 cats" to individual variables:

set data [gets stdin]
scan $data "%d %s" myint mystring

Edit: Added more information from Colin's comment.


puts -nonewline "Enter your name: "
flush stdout
set name [gets stdin]

puts "Hello $name"
0

精彩评论

暂无评论...
验证码 换一张
取 消