Skip to main content
Inspiring
November 1, 2010
Question

Problem Escaping Backslashes and Quotes in CFEXECUTE

  • November 1, 2010
  • 1 reply
  • 2822 views

I'm having trouble getting CFEXECUTE to properly pass arguments through to the command line.

Specifically, when passed \" (literal quote) the command line sees \\" (literal backslash, quote) instead.

This only happens for the FIRST instance of a backslash.

If I set up a variable called theArgumentsString, for example, by doing the following:

<CFSET theArgumentsString = "-a -b ""c \""d\"" ""e""">

The string variable itself is fine.  I get the following (expected) as the value of theArgumentsString:

-a -b "c \"d\" "e"

However, the command that runs does not get the same arguments.

It gets:

-a -b "c \\"d\" "e"

There is an extra backslash added in front of the first backslash.

I've tried passing in an array of arguments instead of a string, and the same thing happens.

I have no idea which end (CF or Windows) is causing the problem.

It only happens on the very first backslash present.

For example, if I pass in the arguments:

\"\"\"\"

What gets passed run on the command line is:

\\"\"\"\"

Running the command manually (with the proper arguments) from the command prompt works fine.

Running it from a batch file works fine, too.

Only when running from CFEXECUTE does the extra \ get added.

We're running...

Server ProductColdFusion
Version9,0,1,274733
EditionStandard
Operating SystemWindows Server 2008 R2
OS Version6.1
Adobe Driver Version4.0 (Build 0005)

Any ideas?  And can anyone reproduce this (on other OSs/CF builds)?

    This topic has been closed for replies.

    1 reply

    Miguel-F
    Inspiring
    November 3, 2010

    What are your intended results for the argument string?  Are you trying to escape the quotation (") marks?

    I am using the cfexecute tag on CF 8.0.1, Windows Server 2003 SP2.  I also have one particular call that includes the backslash character in the arguments field.  It looks something like this: arguments="use #sharename# #userpassword# /user:#servername#\ShareUser".

    A couple of thoughts:

         Have you tried to add your argument string directly to the cfexecute arguments parameter instead of using a variable?  See if it works differently.

         If you are trying to escape the quotation marks then try using two quotes instead of backslash quote; like this arguments="-a -b ""c"" ""d"" -e"

    Inspiring
    November 3, 2010

    The command line I want to run is a GIMP batch job.

    Basically:

    gimp-console-2.6.exe -i -b "(script-name \"Path\\To\\File.ext\" script par am at ers)" -b "(gimp-quit 0)"

    Since the paramter for the -b argument must be enclosed in "()", any quotes in the arguments must be escaped (such as quotes for file paths that may contain spaces). Thus, for the GIMP arguments, I have to escape backslashes (\ -> \\) and some quotes (" -> \"),

    In CF, I am properly escaping the quotes with double quotes (" -> "") on top of the escaping for GIMP.

    It doesn't matter whether or not I specify the arguments in the CFEXECUTE tag explicitly or as a pre-generated variable - the same escape sequence must be performed.

    I tried inline with the CFEXECUTE tag at first, then I moved to using a variable when I wanted to debug (dump the variable out to a text file).

    The variable I generate is correct - \"Path\\To\\File.ext\" stays as \"Path\\To\\File.ext\" in the text file.

    But the command that runs has \\"Path\\To\\File.ext\" .

    This is either an error with CF or with Windows.

    I ended up just outputting the commands to a batch file, then executing the batch file.

    That works fine.  So I'm betting the error is with Coldfusion, and have filed a bug report.