views:

59

answers:

2

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

toto has:"tutu titi"

args is an array of 2 Strings

toto
has:tutu titi

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

has:"tutu titi"

How should I do that?

Edit: I have already tried escaping the quotes with backslash from "Arguments" line in Netbeans propject properties, but I get args[1]

has:\tutu titi\
+4  A: 

This really depends on your shell. You haven't said what operating system you're using. For example, on Windows this will work:

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

I believe the same thing will work in bash, too.

But if you're asking what you can do within Java to resolve this: nothing. The shell will have parsed the command line before the process was invoked, and you can't undo that parsing.

Jon Skeet
Sorry, I forgot to mention I was trying this within Netbeans...
rds
+1  A: 

Use

toto "has:\"tutu titi\""
Riduidel
In a shell, has:"tutu titi" is already considered as a single argument. There is no need to add extra quotes around.
rds
@rds: There is when you've escaped the quotes.
Jon Skeet