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 Profile photo of Richard Schaefer Richard Schaefer 6 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36311
    Profile photo of Richard Schaefer
    Richard Schaefer
    Participant

    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\" 
    "14" 
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop\Metrics.exe" 
    "d:\a6\RWS_Test_Batch_XML\Microsoft_Build_XML\trunk" 
    

    And I get this error:

    Run-Metrics.ps1 : A 
    positional parameter cannot be found that accepts argument 'Studio'.
        + CategoryInfo          : InvalidArgument: (:) [Run-Metrics.ps1], ParentCo 
       ntainsErrorRecordException
        + 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:

    Param
    (
        # AHP Iteration
        [Parameter(Mandatory=$false,Position=0)]
        [int]$AHPIteration,
    
        # buildAnalysisCount
        [Parameter(Mandatory=$false,Position=1)]
        [int]$buildAnalysisCount,
    
        # buildAnalysisNames
        [Parameter(Mandatory=$false,Position=2)]
        [string]$buildAnalysisNames,
    
        # buildAnalysisTypes
        [Parameter(Mandatory=$false,Position=3)]
        [string]$buildAnalysisTypes,
    
        # buildAnalysisAsmbs
        [Parameter(Mandatory=$false,Position=4)]
        [string]$buildAnalysisAsmbs,
    
        # FXCop Level
        [Parameter(Mandatory=$false,Position=5)]
        [int]$FXCopLevel,
    
        # FXCopCmdPath
        [Parameter(Mandatory=$false,Position=6)]
        [string]$FXCopCmdPath,
    
        # FXCop Ruleset Path
        [Parameter(Mandatory=$false,Position=7)]
        [string]$FXCopRulesetPath,
    
        # Visual Studio Version
        [Parameter(Mandatory=$false,Position=8)]
        [string]$msvsversion,
    
        # Metrics Command Path
        [Parameter(Mandatory=$false,Position=9)]
        [string]$metricsCommandPath,
    
        # Working Path
        [Parameter(Mandatory=$false,Position=10)]
        [string]$workingPath
    )
    

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Richard Schaefer
    Richard Schaefer
    Participant

    That was It! Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.