• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java command-line input argument??

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The output of java Project "xxx" and java Project xxx are the same. What is the difference between using and not using the double quote??
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The quotes "" are stripped away by the command line shell before the Java runtime sees them. The shells have different behaviour on different systems. Also IDEs handle command line arguments differently.

With BlueJ, for example, I have to enter "\"xxx\"" to get "xxx" into your program.
With Linux, I have to enter '"xxx"' (using single quotes) to get "xxx" into your program.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnx for the reply, Bart. But what is the answer to this quesstion?



java Regex2 "\d*" ab34ef

and

java Regex2 \d* ab34ef

will have different result...why??
[ July 30, 2006: Message edited by: Jon Lee ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bart?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On linux using bash, for example, the \ gets stripped away from the \d* and the Java runtime sees only the d*.

But \\d* does work. The java runtime sees \d*.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops, sorry, Barry...

Actually my question is the double quote, why the double quote on the command-line argument makes a difference of program output....

Barry???
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because with the double quotes, the shell leaves the string alone (except for stripping away the quotes), while without them, it performs several transformations before passing the string to the calling program. Besides handling escaped characters -which you are experiencing- the shell would also substitute environment variables (if the string contains something like "%FOO%"), and globbing of file names containing wildcards.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic