Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

exec $env(COMSPEC) /c file_with_(parenthesis)

128 views
Skip to first unread message

Chris Niemira

unread,
Dec 28, 2003, 11:46:52 PM12/28/03
to
I've noticed a rather annoying problem on Windows that I can't seem to
find a workaround for. Perhaps someone else has seen it too...

exec $env(COMSPEC) /c $file

Tends to work just fine, unless the value of $file (i.e. the name of the
file I'm tring to open) has a set of parenthesis in it. No matter what I
do, I'm unable to properly escape the value passed to exec. I believe
I've gone through every combination of curly braces, quotes, escapes,
and multiple escapes. Anyone else seen this?

-CN

Chris Niemira

unread,
Dec 29, 2003, 3:14:04 PM12/29/03
to
> exec $env(COMSPEC) /c $file
> Tends to work just fine, unless the value of $file (i.e. the name of the
> file I'm tring to open) has a set of parenthesis in it.

Okay, so I've done a bit more looking into this and discovered that
the issue I'm having is 1/2 due to Windows and 1/2 due to Tcl. In
order to open a file whose name contains () with cmd.exe from a
regular Windows command prompt, one does this:

C:\Temp>cmd /c ""new(1).gif""
C:\Temp>

Because if you're using special characters with '/c'... "old behavior
is to see if the first character is a quote character and if so, strip
the leading character and remove the last quote character on the
command line, preserving any text after the last quote character."

So the first and last quotes are stripped, preserving a useful set of
quotes that escapes the parenthesis. Windows oddness sure, but I'll
deal with it (unless someone cares to tell me that I'm way off base
doing it this way). Of course, trying this all with Tcl yeilds
slightly different results...

% exec $env(COMSPEC) /c {""new(1).gif""}
The filename, directory name, or volume label syntax is incorrect.
%

Okay, slip an echo in there to see if everthing is working properly,
and...

% exec $env(COMSPEC) /c echo {""new(1).gif""}
\"\"new(1).gif\"\"
%

Suddenly there are *escaped* quotes being passed. Am I wrong, or is
TCL auto-escaping my quotes (because of the curly braces?)? How do I
pass unescaped quotes through exec?

I'm currently using Win2k and Tcl 8.4.5

-CN

Brian Toby

unread,
Jan 5, 2004, 10:39:53 AM1/5/04
to
This suggestion goes in the category of lame work-arounds, but have
you considered use of something like this:

set winname [file nativename new(1).gif]

to get an alias name that does not require all those messy quotation
marks?

Brian

0 new messages