Print statement and Return values

Print Statement

Use the puts command to write a string to an output channel. Predefined output channels are “stdout” and “stderr.”  If you do not specify a channel, then puts will display text to the stdout channel.  

Example:

set a [ myprog arg1 arg2 ]

puts "the answer from myprog was $a (this text is on stdout)"

puts stdout “this text also is on stdout”

Return Values

The return code of a Tcl command is a string. You can use a return value as an argument to another function by enclosing the command with square brackets [ ].

Example:

set a [ prog arg1 arg2 ]

exec $a

 

The Tcl command “exec” will run an external program. The return value of “exec” is the output (on stdout) from the program.

Example:

set tmp [ exec myprog ]

puts stdout $tmp