views:

60

answers:

1

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.

+1  A: 

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 :)

Jon Skeet
Thanks. So it seems like the choice should be a single setLine, or multiple setValues, and that the code I'm looking at is not optimal.
smackfu
Yup, that's basically it.
Jon Skeet
+1 because it's a good answer, and I _really_ want to see what happens when you reach 100k.
seth