Running an EXE file using PowerShell from a directory with spaces in it

后端 未结 2 885

I\'m trying to run MSTest.exe from C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE. What\'s more, I\'m taking all of the assemblies in my cu

相关标签:
2条回答
  • 2020-12-15 10:27

    I would recommend you to use an array of parameters and the operator &. See the examples in my answer in here: Executing a Command stored in a Variable from Powershell

    In this case the code should be something like this:

    $MSTestCall = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
    $MSTestArguments = @('/resultsFile:out.trx', '/testsettings:C:\someDirectory\local64.testsettings')
    
    foreach($file in Get-ChildItem $CurrentDirectory)  
    { 
        if($file.name -match "\S+test\S?.dll$" ) 
        { 
            $MSTestArguments += "/TestContainer:" + $file
        } 
    } 
    
    & $MSTestCall $MSTestArguments
    
    0 讨论(0)
  • 2020-12-15 10:31

    Does this work?

    $MSTestCall = @'"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"'@
    
    0 讨论(0)
提交回复
热议问题