Firstly, there is a missing } in thecode.
It looks like a problem with using strings with lists commands.
foreach word [lrange $line 1 end] {
This is not needed, a simple
set temp [lrange $line 1 end]
will do exactly the same thing.
You use split to split each line of input from the exec, but you don't split the $line var into a list, so lindex can be used on it.
while changing the problem above, you could simply change the line
set temp ""
to
set line [split $line]
Note, you should not use args in your proc argument definitions. args has a special use in Tcl, arg, rest, test, to name a few are more suitible values.