Using ArgumentListBuilder with quoted parameters

81 views
Skip to first unread message

Ido Ran

unread,
May 16, 2013, 7:56:08 AM5/16/13
to jenkin...@googlegroups.com
Hi,
I need to build a command line to execute MSTest (I'm the writer of MSTestRunner plugin) that can handle spaces in one of the parameters I pass to MSTest.
The parameteris of the form /testcontainer:file-without-spaces.dll when there are no space and of the form /testcontainer:"file with spaces.dll" when there are spaces either in the file itself or the path to it.

The problem is I can't find a way to use ArgumentListBuilder to build such parameter. It either put quotes around the whole parameter which result in "/testcontainer:file with space.dll" which is not good for MSTest or no quotes at all which cause MSTest to parse the file in the middle and treat the rest of the file name as new parameter.

I've also try to abandon ArgumentListBuild and use StringBuilder but then Jenkins put a single quote around my whole command.

How can I make Jenkins run command such as "Full Path To MSTest\MSTest.exe" /noisolation /testcontainer:file1.dll /testcontainer:"c:\test\test2.dll"

Thank you,
Ido

Jesse Glick

unread,
May 16, 2013, 10:59:18 AM5/16/13
to jenkin...@googlegroups.com
On 05/16/2013 07:56 AM, Ido Ran wrote:
> ArgumentListBuilder […either puts] quotes around the whole parameter which result in "/testcontainer:file with space.dll" which is not good for MSTest

Sounds like MSTest has a nonstandard way of interpreting quotes. Clearly this is Windows-specific since on Unix handling of quotes is done entirely on the caller side,
e.g. the shell; in the case of programmatic execution from ProcessBuilder.<init>(String[]) quoting would be redundant. Windows however forces each application to
interpret quotes in its own command line, e.g. by reading argv as produced by MSVCRT.

Are there are other Windows applications which accept /option:"some value" but reject "/option:some value"? If this is in fact commonplace, then I guess
ArgumentListBuilder should be patched to move the opening quote past anything that appears to be an option name. The standard parser ought to accept either form from what
I can tell.

Ido Ran

unread,
May 16, 2013, 11:06:12 AM5/16/13
to jenkin...@googlegroups.com
I'm not sure if there are other Windows application that treat parameters like /param:"value with space" but I do know MSTest needs it.
Before we are going the way of patching the ArgumentListBuilder, is there a way that I can manually do it?
When I try to use a StringBuilder and pass the whole command as one string Jenkins still add single quote around my whole command which fail to run that way.

I think a method such addKeyValuePair that accept the parameter name and value can do the trick.

Ido

Jesse Glick

unread,
May 16, 2013, 11:17:55 AM5/16/13
to jenkin...@googlegroups.com
On 05/16/2013 11:06 AM, Ido Ran wrote:
> Before we are going the way of patching the ArgumentListBuilder, is there a way that I can manually do it?

The add(…) overloads are irrelevant, since the quoting is done later, by toWindowsCommand. But I am not sure what your question is, since AFAIK if ArgumentListBuilder
does not suit your needs you can simply not use it, and then ultimately LocalProc calls new ProcessBuilder(String[]) which allows you to pass whatever you like.

Ido Ran

unread,
May 16, 2013, 11:49:14 AM5/16/13
to jenkin...@googlegroups.com
I'm not using toWindowsCommand.
When I use simple string array to hold the command and parameters I still get this command:

[workspace] $ '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"' /resultsfile:result.rsx /noisolation '/testcontainer:"c:\temp\dir with space$\test1.dll"'

Notice the red single quote around the arguments that have space in them.

How can I get rid of them?

Jesse Glick

unread,
May 16, 2013, 12:11:50 PM5/16/13
to jenkin...@googlegroups.com
On 05/16/2013 11:49 AM, Ido Ran wrote:
> [workspace] $ '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"' /resultsfile:result.rsx /noisolation'/testcontainer:"c:\temp\dir with space$\test1.dll"'
>
> Notice the red single quote around the arguments that have space in them.

What is echoed to the build log has only a tenuous relationship to the arguments that are finally passed to ProcessBuilder, I am afraid, so do not pay too much attention
to the log and see what is really happening with a Java debugger.

Ido Ran

unread,
May 16, 2013, 12:20:38 PM5/16/13
to jenkin...@googlegroups.com
I see, thank you for the help.
I hope I'll be able to solve this soon.

Ido




--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/dDYW9V6J3R4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages