This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 191254

Summary: Command line parameters do not respect double quotes in windows
Product: projects Reporter: tusharvjoshi <tusharvjoshi>
Component: AntAssignee: Jesse Glick <jglick>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P3    
Version: 7.0   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:

Description tusharvjoshi 2010-10-22 13:04:53 UTC
When I run a Java program with arguments the behaviour of NetBeans IDE is different than the command prompt in Windows XP.

Scenerio:

1) Create a basic Java application which prints all the arguments passed on command line
2) Build the project and run the class from command line like follows:

 java MyClass toto "has:\"toto titi\""

The output will be

 toto
 has:"toto titi"

The double quotes are escaped properly and the Java program received only two arguments

Now set this same arguments in NetBeans Project properties Run node Arguments text box

Run the project from NetBeans IDE and the output is as follows:

 toto
 has:\titi
 tutu\

The Java program received three parameters and all the quotes are eaten (missing)

I tried different workarounds in the arguments text box but cannot find any workaround to pass double quotes to the Java program in Windows XP

[Same program in Max OS X has different behavior and I was able to pass the parameters as two parameters by configuring the argument text box as 

 toto 'has:"toto titi"' 

that is enclosed in single quotes
Comment 1 Tomas Zezula 2010-10-25 16:05:16 UTC
The value is just passed to Ant's java as arg line.
Comment 2 Tomas Zezula 2010-10-25 16:12:40 UTC
 Ant will try to split the command line in a way similar to what a (Unix) shell would do.
Comment 3 tusharvjoshi 2010-10-25 16:45:41 UTC
I understand that the arguments are passed to the ant target as arg element.
My point is the behavior shown by Windows Command Prompt and the NetBeans IDE shall be same on Windows.

This may be a bug with the ANT component NetBeans IDE is using, but for the user the perception is what they are getting from command line is not available through NetBeans IDE GUI.

It will also be worthwhile to think about any workaround, any escape sequence which can be passed through the NetBeans IDE GUI to achieve this somehow.  

This may be an issue with the ANT component, in that case still we will have to find out workaround for ANT issue, as NetBeans IDE internally uses ANT.

with regards
Tushar Joshi, Nagpur
Comment 4 Jesse Glick 2010-10-25 16:54:32 UTC
Handling metacharacters in Unix command-line parsing is difficult, and Windows behaves completely differently. The best we can do is pass <arg line="${something}"/> to Ant, which tries to parse this out as best it can, but in general passing metachars such as spaces will not work well when they have to be encoded and then decoded this way. Configuring a variable-length list of arguments as separate properties is not an option because (without using <script> or specialized tasks) it is not possible for an Ant script to pass execution args of a statically unknown length except by line="...".

If your app really needs specialized CLI arguments, it is best to override the run target in build.xml and pass them in as <arg value="..."/>, which bypasses the escaping/unescaping system. (At least on Unix; I have no idea what Windows will do.)

Safer is probably to have a config file in a format of your choice with detailed information, and just pass the location of this config file to the app.