Subject: passing tcl list to args of an external program (Thx for soln)
From: anonb6e9@nyx.net (Name withheld by request)
Date: 12/1/2007 4:07:28 AM
Thanks Glenn.
In article <slrnfku4i4.qp6.glennj@smeagol.ncf.ca> you write:
>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
just wanted to thank you for the above soln, which worked on
cygwin (tcl 8.4) - thanks very much!
>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
I'm not sure if tcl 8.5 is available for cygwin - looks
like interesting syntax above - will save the 8.5 soln for later
|