• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to pass a command line argument value with white space in between?  RSS feed

 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for example, I want to pass 'Hello Word.docx' and 'Winston' (both without quotes) as a command line argument as I execute the main method

Is it possible to pass 'Hello World.docx' as a whole word?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, on the command line, put it in double quotes, like this:

C:\MyProject> java "Hello World.docx"

You won't see the double quotes in your program; they are only there to let the Windows command prompt know that you mean this to be a single argument instead of two separate arguments.
 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow thank you so much.
I tried it and it works.

But what if I want to include an open and close quotation marks between text as part of the argument?
Is it possible to pass "Hello World" with open and close quotes?

I tried ""HELLO"" and the JVM seems neglect all "" leading and end of text
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried an escape sequence: "\"Hello World\"" ?
 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it worked using escape sequence

Thank you very much.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!