Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing strings with delimited characters to external applications

Status
Not open for further replies.

AndoSam

Technical User
Jul 14, 2010
16
GB
I am currently writing a tcl/tk script that communicates with an external application. I have succesfully managed to extract a string and process it as required. My issue is that some of these strings are of the format xyz[0:2] and therefore need to be passed to the application as xyz\[0:2\] to stop them being interpreted as commands

I have tried using the following
Code:
if [regexp \[.*\] $path] {
set subs1 "\\\["
set subs2 "\\\]"
regsub {\[} $path $subs1 newPath
regsub {\]} $newPath $subs2 $path
}

to substiture the backslashes in. However whenever this variable is used later in the script, even passing it to the application, the new backslash is just interpreted as escaping the square brackets again, returning to the original problem.

Any thoughts?
 
Delayed substitution is always a bummer:
Code:
% set s1 xyz[4:5]
invalid command name "4:5"
% set s1 "xyz[4:5]"
invalid command name "4:5"
% set s1 {xyz[4:5]}
xyz[4:5]
%

_________________
Bob Rashkin
 
Hi

Yeah I've been having quite a lot of issues with it. I had discovered your suggestion of using curly braces to prevent substitution. The main issue came in substituting in the backslashes and preventing them being interpreted.
In the end I came up with a slightly messy solution:
Code:
if [regexp \[.*\] $path] {
	set subs1 "\\\["
	set subs2 "\\\]"
	regsub {\[} $path $subs1 newPath
	regsub {\]} $newPath $subs2 finalPath
} else {
	set finalPath $path
}

But it seems to work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top