Quotes in command line arguments passed to Java main ()

I run a Java program with the following command line (Edit: in NetBeans project properties 6.8)

toto has:"tutu titi" 

args is an array of 2 lines

 toto has:tutu titi 

I want (two arguments really, the second) args[1] be

 has:"tutu titi" 

How can I do it?

Edit: I already tried to execute backslash quotes from the "Arguments" line in the Netbeans properties properties, but I get args [1]

 has:\tutu titi\ 
+4
source share
5 answers

I had a similar problem in NetBeans and found a solution:

Change / add property "application.args" to your private.properties:

 application.args='has:""tutu titi""' 

Single quotes to mark your โ€œargumentโ€ and two double quotes to specify one โ€œdouble quoteโ€.

+3
source

It really depends on your shell. You did not say which operating system you are using. For example, on Windows this will work:

 java Test toto "has:\"tutu titi\"" 

I believe the same will work in bash too.

But if you ask what you can do in Java to solve this problem: nothing. The shell will parse the command line before invoking the process, and you cannot cancel this parsing.

+6
source

Use

 toto "has:\"tutu titi\"" 
+1
source

This is recognized by netbeans as a bug that will not be fixed!

+1
source

When adding NetBeans (7.1.2) from the configuration / arguments dialog box, the outer and hidden double quote with a single quote worked for me, for example:

 my argument 
+1
source

All Articles