4

One of the arguments passed to my java program is like this, ab|cd. Initially, when I run the java program, like this,

$ java className ab|cd

it fails, since | is interpreted in the linux shell as a pipe symbol. So only ab is passed into java program. So I made a second attempt:

$ java className "ab|cd"

This time, "ab|cd" is passed in, but the value includes the double quotes. What the program is really intended to have is ab|cd. How can I pass in the correct value without the quotes?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Richard
  • 14,642
  • 18
  • 56
  • 77

4 Answers4

8

In the command shell, you can escape out characters using the '\' character.

 java className ab\|cd
Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
Steven Mastandrea
  • 2,752
  • 20
  • 26
3

Try (for Linux):

$ java className ab\|cd

For Windows:

java className ab^|cd
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
2

Try this,

"\" is used inorder to nullify the effect of the characters which have special meanings.

java className ab\|cd
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
-2

Maybe try this:

arg="ab|cd"
java className $arg
Adam Sznajder
  • 9,108
  • 4
  • 39
  • 60