Search code examples
batch-filedotcover

Batch - How to pass argument with quotes within other quotes


I'm using dotCover command line tool to run coverage on some Tests. In order for it to run it needs to receive as arguments the path of the "Target executable" which in my case is Nunit and "Target Arguments" which is in my case are the arguments I pass to Nunit. The thing is that one of the arguments I pass to Nunit is a path with white spaces. And when I pass the arguments of Nunit to dotCover it is also surrounded with quotes because it has white spaces. So, for example to run the tests simply on nunit I run the command:

"%NunitDir%\nunit-console-x86.exe" /nologo /noshadow "%DllDir%\Tests.dll" 
 /config=Release /domain=%Domain% /xml=%resultDir%\NUnitTestResults.xml

and to run coverage on tests I need to run something like:

set NunitArgs=/nologo /noshadow "%DllDir%\Tests.dll" 
 /config=Release /domain=%Domain% /xml=%resultDir%\NUnitTestResults.xml

%dotCoverDir%\dotCover.exe cover /TargetExecutable="%NunitDir%\nunit-console-x86.exe" 
 /TargetArguments="%NunitArgs%" /Output="%outputDir%\NUnitTestResults.xml" 

The problem is that NunitArgs already contain quotes, and when I run the dotCover command it only read the arguments from first quotes to the second quotes.


Solution

  • Try /TargetArguments="%NunitArgs:"=""%" or even /TargetArguments="""%NunitArgs:"=""%""".

    Read How Command Line Parameters Are Parsed by David Deley © 2009 (Updated 2014) (especially Windows®: 4. Everyone Parses Differently). Good luck!