How to use a list in tcl as an argument to multiple lines (rather than a single line)?

In particular, let's 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 provide this list as an argument to multiple files with

exec xgraph $bwList -geometry 800x400  &

This will give me an error:
Warning: Cannot open the file `videoBW_ (0) .tr videoBW_ (1) .tr videoBW_ (2) .tr '

Since tcl reads the entire list as one line instead of several lines. Is there a way to read the list as multiple lines?

EDIT:

The solution for tcl8.4 is the one provided by Brian Fenton. but by changing the set exec_call {xgraph $ bwList -geometry 800x400} set exec_call "xgraph $ bwList -geometry 800x400"

Basically, if you just add eval before exec, it does the job.

  eval exec xgraph $bwList -geometry 800x400  &

Fot tcl 8.5 .

+3
4

8.5 :

exec xgraph {*}$bwList -geometry 800x400 &

8.4 :

eval exec xgraph $bwList -geometry 800x400 &
# Or this more formally-correct version...
# eval [list exec xgraph] [lrange $bwList 0 end] [list -geometry 800x400 &]

, 8.5 , , (, , , , , ).

+2

tcl 8.5 , :

exec xgraph {*}$bwList -geometry 800x400  &

{*} . .

5 Tcl .

+4

I do not quite understand what you mean by "multiple lines." This would help me if you showed me what the last xgraph call should look like. I thought with xgraph that the files came at the end (i.e. after -geometry 800x400)?

In any case, which may help, use eval instead of calling exec directly .

set exec_call {xgraph $bwList -geometry 800x400}
set caught [catch {eval exec $exec_call} result]
if { $caught } {
 #handle the error - it is stored in $result
} else {
 #handle the success
}
+2
source

For Tcl 8.4, I would do it like this:

set cmd [concat [list exec xgraph] $bwList]
lappend cmd -geometry 800x400
+2
source

All Articles