Group: comp.lang.tcl


Subject: passing tcl list to args of an external program
From: roa6v@sdf.lNoOnSePsAtMar.org (Anon432 Vqfz)
Date: 11/29/2007 1:36:20 PM
Consider this bash test script: $ bash -c 'for f;do echo "myarg: $f";done' TESTSCRIPT 'first arg' 'second arg' myarg: first arg myarg: second arg How might I drive the arguments sent to the above script with a tcl list? I want the method to to be generic enough, so it does not matter what is in the list. The only approaches that seem to work for me, involve figuring out a way to metaquote the arguments when required. But, I'm inexperienced w/tcl. -- thanks much, Tom -- roa6v@sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org

Subject: passing tcl list to args of an external program
From: Glenn Jackman
Date: 11/29/2007 7:25:55 PM
At 2007-11-29 08:36AM, "Anon432 Vqfz" wrote: > Consider this bash test script: > > $ bash -c 'for f;do echo "myarg: $f";done' TESTSCRIPT 'first arg' 'second arg' > myarg: first arg > myarg: second arg > > How might I drive the arguments sent to the > above script with a tcl list? I want the method > to to be generic enough, so it does > not matter what is in the list. > For tcl 8.4 % set params [list {first arg} {second arg}] {first arg} {second arg} % set cmd [linsert $params 0 bash -c {for f;do echo "$0 arg: $f";done} TESTSCRIPT] bash -c {for f;do echo "$0 arg: $f";done} TESTSCRIPT {first arg} {second arg} % catch [linsert $cmd 0 exec] output 0 % set output TESTSCRIPT arg: first arg TESTSCRIPT arg: second arg for tcl 8.5 % set params [list {first arg} {second arg}] {first arg} {second arg} % set cmdpref [list bash -c {for f;do echo "$0 arg: $f";done} TESTSCRIPT] bash -c {for f;do echo "$0 arg: $f";done} TESTSCRIPT % catch [list exec {*}$cmdpref {*}$params] output 0 % set output TESTSCRIPT arg: first arg TESTSCRIPT arg: second arg > The only approaches that seem to work for me, involve > figuring out a way to metaquote the arguments when required. > But, I'm inexperienced w/tcl. I use this to think about quoting in Tcl: shell quoting: "double $interpolates", 'single $does_not' Tcl quoting: "double $interpolates", {braces $dont} -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry