Calling script from BAT file with file system paths as parameters fails syntax

This topic contains 2 replies, has 2 voices, and was last updated by  Richard Schaefer 2 years, 4 months ago.

  • Author
  • #36311

    Richard Schaefer

    I'm calling this from a BAT file:

    powershell -nologo -file ./Run-Metrics.ps1 1 1 "RWSConsoleOnly" "batch" 
    "RWSConsoleOnly" 3 
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FXCop\FXCopCmd.exe" 
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\" 
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop\Metrics.exe" 

    And I get this error:

    Run-Metrics.ps1 : A 
    positional parameter cannot be found that accepts argument 'Studio'.
        + CategoryInfo          : InvalidArgument: (:) [Run-Metrics.ps1], ParentCo 
        + FullyQualifiedErrorId : PositionalParameterNotFound,Run-Metrics.ps1

    This was working a couple of days ago. I've made changes internally to the script but not to the BAT file or the script parameters. The parameters are:

        # AHP Iteration
        # buildAnalysisCount
        # buildAnalysisNames
        # buildAnalysisTypes
        # buildAnalysisAsmbs
        # FXCop Level
        # FXCopCmdPath
        # FXCop Ruleset Path
        # Visual Studio Version
        # Metrics Command Path
        # Working Path

    Any ideas why I'm getting this error? I've tried more quotes around the strings with spaces in the path and that didn't work. Is there a "best practice" for passing complex strings to a single PS parameters from a BAT file?

  • #36312

    Dave Wyatt

    It's a syntax error in your batch file. In the command prompt, you can escape a quotation mark with a backslash, and you've got a trailing backslash at the end of one of your paths:

    Rule Sets\"

    It should be fine to simply remove that backslash and end the string with Rule Sets". If you really do need that trailing backslash, you can double it up: "Rule Sets\\".

    It's just one of those weird quirks of the old command shell.

  • #36313

    Richard Schaefer

    That was It! Thanks!

You must be logged in to reply to this topic.