Tutorial :Diff between setLine() and setValue() in Ant API Commandline.Argument class?



Question:

I don't understand the difference between these methods.

Here's what the JavaDoc says:

setLine(String) = Line to split into several commandline arguments.

setValue(String) = Sets a single commandline argument.

My confusion is that I see them being used interchangeably in the code I'm updating. An example:

Commandline commandline;  commandline = new Commandline(new File(jarUtilsDir,"signtool.exe").getAbsolutePath());  commandline.createArgument().setLine("--verbosity");  commandline.createArgument().setValue("-1");  commandline.createArgument().setLine("-o");  

Maybe I just need an explanation of how these are supposed to be used.


Solution:1

If you're setting a single value without a space, it doesn't matter. However, suppose you have:

commandline.createArgument().setLine("x y");  

that's equivalent to:

commandline.createArgument().setValue("x");  commandline.createArgument().setValue("y");  

whereas

commandline.createArgument().setValue("x y");  

will do appropriate quoting (I believe) such that the program that's called sees it as a single command line argument.

The easy way to test this is to create an app which just prints out its arguments, one per line, and try both ways :)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »