From: pt on
Hi All,

Need some help.

I have a tcl script getting a variable containing an encrypted
password eg {xor}PG8adGh+NzA=

in the script below the encrypted password is assigned to set
propertyValue [lindex $argvX 3]

however, when the prop_attr variable is set containing $propertyValue
it fails becuase "{ }" are special characters. same applies when
$AdminConfig modify $jvm [list $prop_attr] is executed

I cannot for the life of my figure out have to tell tcl to totally
ignore the curly braces in a variable. Perhaps it can't be done - I
don't know.

I've tried \{ , [list $arg] etc.

If some one can suggest something - I will love you forever!


#--------------------------------------------------------------
# set up globals
#--------------------------------------------------------------
global AdminConfig
global AdminControl
global AdminApp

#--------------------------------------------------------------
# Main
#--------------------------------------------------------------
regsub -all {\\} $argv {/} argvX
set clusterName [lindex $argvX 0]
set serverInstanceNumber [lindex $argvX 1]
set propertyName [lindex $argvX 2]
set propertyValue [lindex $argvX 3]
set propertyDescription [lindex $argvX 4]
set nodeName [lindex $argvX 5]
set wasnode [string toupper $nodeName]

set serverName ""
append serverName $clusterName $wasnode "S0" $serverInstanceNumber

set prop_attr [list systemProperties [list [list [list name
$propertyName] [list value $propertyValue] [list description
$propertyDescription]]]]

#---------------------------------------------------------
# Get a list of cells
#---------------------------------------------------------
set cells [$AdminConfig list Cell]
foreach cell $cells {
#---------------------------------------------------------
# Get a list of clusters in this cell
#---------------------------------------------------------
set nodes [$AdminConfig list Node $cell]
foreach node $nodes {
set servers [$AdminConfig list Server $node]
#---------------------------------------------------------
# Get a list of member servers in this cluster
#---------------------------------------------------------
foreach server $servers {
set servername [$AdminConfig show $server name]
regsub -all {\{name} $servername {} servername1
regsub -all {\}} $servername1 {} servername2
set servername [string trim $servername2]
if {$servername=="$serverName"} {
set jvm [$AdminConfig list JavaVirtualMachine $server]
$AdminConfig modify $jvm [list $prop_attr]
}
}
}
}

$AdminConfig save
From: hae on
Hi,

the argv is a string that is separated by spaces. lindex works with
this as it were a list in most cases but not in yours.

In a real list it works fine

% set tcl_patchLevel
8.4.14
% set a "{xor}PG8adGh+NzA="
% set x [list hallo welt $a]
% lindex $x 2
{xor}PG8adGh+NzA=

In a string it doesn't

% set x "hallo welt $a"
% lindex $x 2
list element in braces followed by "PG8adGh+NzA=" instead of space


Solution:

Make your argvX a list:

% set y [split $x " "]
hallo welt {{xor}PG8adGh+NzA=}
% lindex $y 2
{xor}PG8adGh+NzA=
From: Larry W. Virden on
On Jun 25, 2:13 am, p...(a)paradise.net.nz wrote:
> I have a tcl script getting a variable containing an encrypted
> password eg {xor}PG8adGh+NzA=

Is there a way to take your program and trim off non-relevant pieces
until you have the smallest coherent example of your problem?

Here's why I ask:

$ /usr/tcl84/bin/tclsh
% info patchlevel
8.4.7
$ cat ~/argv.tcl
#! /usr/tcl84/bin/tclsh

set name [lindex $argv 0]
puts $name
$ ~/argv.tcl "{abc}xyz" 123
{abc}xyz

As you can see - the braces don't cause a problem with set or being in
the argv variable. No need to do anything with regexp, etc.

My suggestion is the following.

Take a deep breath, go back to where you were before you started
trying to fix the handling of the { in the value, make a copy of the
program. In the copy, remove all the code after the point where you
are finding the error, as it isn't relevant. Modify the remaining code
so it runs. Then, delete any statement which is unrelated to the
specific assignment giving you grief. Keep testing the fragment as it
gets smaller and smaller. As long as it keeps raising an error, keep
seeing what if anything can be removed.

Eventually, you should be down to a small number of lines that still
exhibit the problem. Make certain that any site specific things -
executables, etc. - are changed to more generic invocations. That way,
anyone should be able to run the code and see the problem.

Let us see that and we should be able to help.

P.S. If the code stops "breaking" during the above process, then the
code you just removed is critical to the situation, so backing out the
changes and focusing on that code is the next step.
From: Bryan Oakley on
hae wrote:
> Hi,
>
> the argv is a string that is separated by spaces.

Correction. argv is a list. Big difference.
From: Bryan Oakley on
pt(a)paradise.net.nz wrote:
> Hi All,
>
> Need some help.
>
> I have a tcl script getting a variable containing an encrypted
> password eg {xor}PG8adGh+NzA=
>
> in the script below the encrypted password is assigned to set
> propertyValue [lindex $argvX 3]
>
> however, when the prop_attr variable is set containing $propertyValue
> it fails becuase "{ }" are special characters. same applies when
> $AdminConfig modify $jvm [list $prop_attr] is executed

FWIW, tcl has absolutely not problem whatsoever storing special
characters in variables. We'll hopefully get to why you're having
trouble below.

> I cannot for the life of my figure out have to tell tcl to totally
> ignore the curly braces in a variable. Perhaps it can't be done - I
> don't know.
>
> I've tried \{ , [list $arg] etc.
>
> If some one can suggest something - I will love you forever!
>
>
> #--------------------------------------------------------------
> # set up globals
> #--------------------------------------------------------------
> global AdminConfig
> global AdminControl
> global AdminApp
>
> #--------------------------------------------------------------
> # Main
> #--------------------------------------------------------------
> regsub -all {\\} $argv {/} argvX

I think your problem starts with that last line. You are taking a valid
list -- $argv -- and converting it to a string (implicitly), and also
converting backslashes to a forward slash. Later, when you are using
lindex, the interpreter first must convert that new string back to a
list, most likely with results you don't expect.

Are you aware, for example, that Tcl may insert backslashes into the
string representation of a list to preserver the "listness" of the data?
If you then remove those backslashes you potentially corrupt the list,
depending on the contents.

Instead, you should be doing that transformation on an
element-by-element basis, for example:

set argvX [list]
foreach element $argv {
regsub -all {\\} $element {/} new
lappend argvX $new
}

If that doesn't help, please show us the exact error you are getting,
and what line of code is throwing that error. And perhaps explain why
you are converting backslashes to forward slashes -- perhaps that can be
avoided or done in a different way.