Shell command with embedded Parentheses

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NthDegree
    New Member
    • Feb 2014
    • 3

    Shell command with embedded Parentheses

    I am trying to construct a string that contains the following and set a string variable to its value as in:
    Code:
    strCommand = "C:\Program Files (x86)\Tripwire\Tripwire Log Center Manager\"TLCcommander\vsqlcmd -d "C:\Program Files (x86)\Tripwire\Tripwire Log Center Manager"\Data\tlc.vdb4 -o vsql.txt -h -1 -s "," -Q "Select * from asc_asset"
    shell strCommand
    I've tried using double quotes, triple quotes in various combinations with no luck.

    Any suggestions?
    Last edited by NeoPa; Feb 4 '14, 04:30 AM. Reason: Added mandatory [CODE] tags.
  • dsatino
    Contributor
    • May 2010
    • 393

    #2
    Assuming your failure is in setting the string variable...

    Change all of you double quotes to single quotes. Then wrap the entire string in double quotes

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32662

      #3
      All double-quotes within your string literal value should be doubled up (and properly formulated of course). Try this :
      Code:
      strCommand = """C:\Program Files (x86)\Tripwire\Tripwire Log Center Manager\" _
                 & "TLCcommander\vsqlcmd"" -d ""C:\Program Files (x86)\Tripwire\" _
                 & "Tripwire Log Center Manager\Data\tlc.vdb4"" -o vsql.txt -h -1 " _
                 & "-s "","" -Q ""Select * from asc_asset"""
      shell strCommand
      Frankly, though I'm not sure of the syntax of the command, it does look wrong. What I suggest you do is get the write value for the string first. When you have an actual working version of the command you'd like to execute then copy/paste that in here and we can help with converting it into a VBA command to set the string up correctly.

      Comment

      • NthDegree
        New Member
        • Feb 2014
        • 3

        #4
        That worked perfectly. Appreciate the help. Just for grins, here is the command as run from a cmd window which also worked. It was the going from cmd window to code that I had the problem.

        C:\>"C:\Program Files (x86)\Tripwire\ Tripwire Log Center Manager\"TLCcom mander\vsqlcmd -d "C:\Program Files (x86)\Tripwire\ Tripwire Log Center Manager"\Data\t lc.vdb4 -o c:\vsql.txt -h -1 -Q "Select * from asc_asset"

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #5
          That's interesting. As a bit of a CMD fan myself, I was unaware that parts of a full file reference could be enclosed in quotes while the rest of it could follow outside of them. I'd assumed the whole reference needed to be within quotes for it to work. You'll see this reflected in the VBA I posted. The result is changed from your original for that very reason.

          :-) I learned something today.

          Comment

          • NthDegree
            New Member
            • Feb 2014
            • 3

            #6
            As did I. I didn't think you could have the program name inside the quotes. I thought it would be considered part of the path.

            Again, thanks for the assist.

            Comment

            Working...