Specifically lets say i create a list with :
for {set i 0} {$i < $val(recv)} {incr i} {
lappend bwList "videoBW_($i).tr"
close $videoBW_($i)
}
and then i want to give that list as an argument of multiple files with
exec xgraph $bwList -geometry 800x400 &
It will give me the error:
Warning: cannot open file `videoBW_(0).tr videoBW_(1).tr videoBW_(2).tr'
Because tcl reads the whole list as one string instead of multiple strings. Is there a way to read the list as multiple strings ?
EDIT :
The solution for tcl8.4 is the one Brian Fenton provided. but by changing set exec_call {xgraph $bwList -geometry 800x400} to set exec_call "xgraph $bwList -geometry 800x400"
Basically if you only add eval in front of exec it does the job .
eval exec xgraph $bwList -geometry 800x400 &
Fot tcl 8.5 Bryan Oakley provided a more elegant solution.
If you are using tcl 8.5 or later you can do:
exec xgraph {*}$bwList -geometry 800x400 &
{*} is called the expansion operator. It expands lists into individual elements before the statement is executed.
See section 5 of the Tcl man page for the definitive explanation.
In 8.5 and later:
exec xgraph {*}$bwList -geometry 800x400 &
In 8.4 and before:
eval exec xgraph $bwList -geometry 800x400 &
# Or this more formally-correct version...
# eval [list exec xgraph] [lrange $bwList 0 end] [list -geometry 800x400 &]
As you can see, the 8.5 expansion syntax helps a lot, and that's particularly true as you go from simple experimentation to production code (e.g., if you're adding a label argument with spaces in to that command line; the expansion version will just handle it correctly, but with the old version you'll get into having to quote everything up properly, which you can see is very messy above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With