0

I just made the installation of jflex and cup and I want to test if everything is ok. Here is what I write in the shell and the result I get. enter image description here

Here is the content of jflex.bat file: enter image description here Is there something I have done wrong? How to run for first time jflex? When I write java -version it displays the correct version of java in my pc. THe problem is with jflex.

Thanks!

John Dow
  • 47
  • 2
  • 7
  • Please include graphics by using the `picture` icon (like a landscape) so that future readers may see what the data was. Best to cut-and-paste code snippets, then select and press `{}` to mark as code. That way, your code is editable and doesn't have to be retyped with consequent saving in typos. – Magoo Nov 21 '16 at 00:08
  • ...or you could have copy-pasted the text from the console into your question. Because there is no way for a future user to find your question by searching the error message shown in a picture. – Seki Jan 21 '17 at 12:36

2 Answers2

1

You need to surround the value of the JAVA_HOME variable with double quotes because it contains spaces The JAVA_HOME variable that contains the path to the root-directory of your java environment contains spaces: C:\Program Files (x86)\Java. It is used at the 3rd last line:

%JAVA_HOME%\bin\java -classpath...

So by just substituting the value of %JAVA_HOME% you get:

C:\Program Files (x86)\bin\java -classpath...

You would say: "it's just a path to the java executable". But that's not how the command interpreter sees it, it will think you are giving 3 different things: C:\Program Files (x86) (it just takes the whitespace as separator for arguments as usual!). It then will take the first one C:\Program as the path to an executable program and the rest of the line as its arguments. Because C:\Program is not the path to a valid executable you get the error

'C:\Program' is not recognized as an external or internal command`

So to let it know he always has to see the C:\Program Files (x86) as a whole (part of a same thing: one path to a directory) you just surround it with double quotes. In batch it is always wise to surround variables with double quotes when they represent a path! Now you have 3 options:

  1. The most easy one (will only solve this specific problem): replace

    set JAVA_HOME=C:\Program Files (x86)\Java
    

    with

    set JAVA_HOME="C:\Program Files (x86)\Java"
    

    This way you make sure everywhere JAVA_HOME is used, you will get no more problems because of the spaces arround "Files"

  2. Go everywhere you used %JAVA_HOME% and replace it with "%JAVA_HOME%" (just surround with double quotes). You can do the same for all usages of %JFLEX_HOME% as this also represents a path

  3. The last option (the most general, one you should consider as a rule in batch) surround all representations of paths (literal paths or paths set in variables) with double quotes.

J.Baoby
  • 2,167
  • 2
  • 11
  • 17
  • But the java is Ok. When I write java -version it displays the correct version of java in my pc. THe problem is with jflex. – John Dow Nov 22 '16 at 20:57
  • There is no problem with your java (or at least ... it is not what causes the error) – J.Baoby Nov 22 '16 at 21:46
  • I edited my answer and provided some more explanation, hope it helps you to understand the problem and to solve it :) – J.Baoby Nov 22 '16 at 21:47
1

Where you are executing %java_home%\bin, you should

1) Enclose %java_home%\bin\java in "Double Quotes"
2) Likewise, enclose %clpath% in "Double Quotes"

That way, cmd is aware that the contents between the quotes is a single string.

Magoo
  • 77,302
  • 8
  • 62
  • 84