How to Get User Input in Tcl

Advertisement

Advertisement

There are many situations where it is useful to ask the user for some information while a program is running. Tcl makes this a breeze. Check out these code snippets that demonstrate how to interact with the user and manipulate input.

# Present a message
puts "Enter a value: "

# Get input from standard input (keyboard) and store in $someVar
gets stdin someVar

# Output the results
puts "You entered: $someVar."

Note that gets also works on files not just standard input

Advertisement

Advertisement