Wrap command in a CMD.EXE call so we can return the exit code (ERRORLEVEL). This method takes care of escaping special characters in the command, which is needed since the command is now passed as a string to the CMD.EXE shell. This is done as follows: Wrap arguments in double quotes if they contain any of: space *?,;^&<>|" and if escapeVars is true, % followed by a letter.
When testing from command prompt, these characters also need to be prepended with a ^ character: ^&<>| -- however, invoking cmd.exe from Jenkins does not seem to require this extra escaping so it is not added by this method.
A " is prepended with another " character. Note: Windows has issues escaping some combinations of quotes and spaces. Quotes should be avoided.
If escapeVars is true, a % followed by a letter has that letter wrapped in double quotes, to avoid possible variable expansion. ie, %foo% becomes "%"f"oo%". The second % does not need special handling because it is not followed by a letter.
Example: "-Dfoo=*abc?def;ghi^jkl&mno
stu|vwx""yz%"e"nd"
@param escapeVars True to escape %VAR% references; false to leave these aloneso they may be expanded when the command is run
@return new ArgumentListBuilder that runs given command through cmd.exe /C
@since 1.386