Pass an argument starting with '@' to jcommander

I use JCommander (version 1.32) to parse the command line arguments passed to the java application (call it app). The problem is that one of the arguments I need to pass begins with @, and as you can see here there is a special syntax for @. So the application call with app @argfails with

Failed to read arg: java.io.FileNotFoundException: arg file (There is no such file or directory).

After reading this information, I tried to put my arguments in a file, but apparently the "@ syntax" is recursive, so even when I put @argin a file, my program crashes with the same error.

Is there a way to pass an argument starting with @to a program using jcommander? Is there a way to disable syntax @?

+4
source share
1 answer

As a result of the chat discussion about this between the OP and me, we came to the following conclusion:

JCommander calls himself as part of how he analyzes command structures - subcommands, each of which has its own parameter definitions.

At the top level, it extends the @ parameter and creates a new argument list that includes the contents of the file.

Then, when he calls himself, he parses this argument list again and, therefore, expands again the parameters starting with the character @.

, , , . , , , @, . , :

file1.txt

@file2.txt

file2.txt

@actualparameter

@file1.txt .

, . , :

  • .
  • JCommander, @ .
  • kludge, , @, , . , .

: Jcommander .

pull Jcommander github, @, .

JCommander jc = new JCommander(params);
jc.setExpandAmpersat(false);

, 1.54.

+5

All Articles