3

I am using PowerShell to compose a command to execute OpenCover which has a flag -filter

However it turns out that Filter is one of the reserved words in PowerShell.

The command that I generate (which runs fine under CMD) is:

OpenCover.Console.exe -output:Coverage.xml -register:user -filter:"+[*]* -[*]*.Test*" -target:nunit-console.exe -targetargs:"Test.dll /config:Release /noshadow /nologo /labels"

But when I run it inside PowerShell I get an error:

Incorrect Arguments: The argument [*]*.Test* is not recognised
Community
  • 1
  • 1
MaYaN
  • 6,683
  • 12
  • 57
  • 109

2 Answers2

3

This have nothing to do with filter being reserved word in PowerShell. The problem in how PowerShell pass parameters to native application. Your command line will be passed as:

OpenCover.Console.exe -output:Coverage.xml -register:user "-filter:"+[*]* -[*]*.Test*"" -target:nunit-console.exe "-targetargs:"Test.dll /config:Release /noshadow /nologo /labels""

Some extra quotes, added by PowerShell, cause that wrong command line will be passed to native application.

First thing you can try, is to change command line to following:

OpenCover.Console.exe -output:Coverage.xml -register:user "-filter:+[*]* -[*]*.Test*" -target:nunit-console.exe "-targetargs:Test.dll /config:Release /noshadow /nologo /labels"

In that case, no extra quotes will be added by PowerShell, and possible that OpenCover.Console.exe can recognize your command.

If that does not help, than you could use Start-Process cmdlet, it never add any extra qoutes:

Start-Process OpenCover.Console.exe '-output:Coverage.xml -register:user -filter:"+[*]* -[*]*.Test*" -target:nunit-console.exe -targetargs:"Test.dll /config:Release /noshadow /nologo /labels"' -NoNewWindow -Wait
user4003407
  • 21,204
  • 4
  • 50
  • 60
0

Have you tried reading the "about_Escape_Characters" section on PowerShell technet? https://technet.microsoft.com/en-us/library/hh847755.aspx

STOP-PARSING SYMBOL

When calling other programs, you can use the stop-parsing symbol (--%) to prevent Windows PowerShell from generating errors or misinterpreting program arguments. The stop-parsing symbol is an alternative to using escape characters in program calls. It is introduced in Windows PowerShell 3.0.

For example, the following command uses the stop-parsing symbol in an Icacls command:

icacls X:\VMS --% /grant Dom\HVAdmin:(CI)(OI)F

For more information about the stop-parsing symbol, see about_Parsing.

Chris
  • 304
  • 7
  • 21