• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in command line args  RSS feed

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant we use either ( or ) as a command line argument in java.
I get a syntax error on doing this . But it works in this way \( or \)
PS:-
I think this works in java version 1.4
[ November 13, 2005: Message edited by: Srinivasa Raghavan ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't care, but your shell probably does. Remember that when you type a command line, your command interpreter (cmd.exe, or bash, or whatever) sees it first, and that command interpreter might attach a special meaning to parentheses. Escaping them at the shell is simply telling the shell to ignore them, to let Java see them without trying to interpret them first.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks EFH. I'm running this in "KSH" , so do you say this shell gives a special meaning to this character and treats it as a syntax error in a unix command .
I even tried this in 1.4 but doesnt work.

This is the error i'm getting :

ksh: syntax error: `(' unexpected
[ November 13, 2005: Message edited by: Srinivasa Raghavan ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, parentheses on a ksh command line (as with many UNIX shells) mean "run this in a separate shell." Other characters that would be perfectly good Java program arguments, but which would need to be escaped for the shell to pass them through, include "&", "<", ">", "!", and others.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot EFH.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!