vbs how to execute a command with quoted parameters


  1. Posts : 16
    Win7
       #1

    vbs how to execute a command with quoted parameters


    Hi,

    OS: Win7 64bits Family

    Can't find the way to fix quoting issue.

    Suppose in the command prompt this works:

    "c:\what ever\my program.exe" "d:\some dir\my file.txt" cat 1-2 output "d\some dir\_out.txt"

    How do I make this into some vbs scripting?

    I tried this:
    Code:
    exePath= "c:\what ever\my program.exe"
    spath= "d:\some dir\"
    iFile = spath & "my file.txt"
    oFile= spath & "_out.txt"
    iNumber=2
    
    cli = Chr(34) & exePath & Chr(34) & " " & Chr(34) & sFileSelected  & Chr(34) & " cat 1-"& iNumber & " output  "  & Chr(34) & oFile & Chr(34)
    Dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    Cmd=Chr(39) & cli & Chr(39) 
    objShell.Run(Cmd)
    Set objShell = Nothing
    I get:
    error 80070002 “The system cannot find the file specified”

    Thanks
      My Computer


  2. Posts : 2,468
    Windows 7 Ultimate x64
       #2

    From a quick read, there is no variable named sFileSelected (as it's used in the concatenation).
    Instead, it should be created from concatenating spath and iFile, declared earlier.
      My Computer


  3. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #3

    Alejandro85 said:
    [sFileSelected] should be created from concatenating spath and iFile
    And preferable using the 'BuildPath' method of the 'Scripting.FileSystemObject' com object.

    The value of cli after line 7 is,
    Code:
    "c:\what ever\my program.exe" "" cat 1-2 output  "d:\some dir\_out.txt"
    The second set of double quotes is missing its content. Consider replacing sFileSelected with 'spath & iFile', or define the variable sFileSelected as such before you reference it, Live.
      My Computer


  4. Posts : 16
    Win7
    Thread Starter
       #4

    Oups, I wanted to make it simpler than actually (opens a file selection window)

    The line being, but doesn't change anything to the issue:
    Code:
    cli = Chr(34) & exePath & Chr(34) & " " & Chr(34) & iFile & Chr(34) & " cat 1-"& iNumber & " output  "  & Chr(34) & oFile & Chr(34)
      My Computer


  5. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #5

    I'm failing to make sense of your problem. What exactly are you trying to do?
      My Computer


  6. Posts : 16
    Win7
    Thread Starter
       #6

    Code:
    What exactly are you trying to do?
    Execute some command line tools having quoted parameters from a vbs script (bat file).

    the error was:
    Cmd=Chr(39) & cli & Chr(39)

    Doesn't need to be quoted
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:20.
Find Us