'C:\Program' is not recognized error

94,597

Solution 1

Okay, that makes it clearer.

There are two main problems here.

First of all, the reason you're getting 'C:\Program' is not recognized... is, of course, because it contains spaces. The fact that you have it quoted in the PATH environment variable has no relation to how %JAVA_HOME% is interpreted at the prompt. You have two options.

  1. Quote it when you define the variable, i.e. set JAVA_HOME to "C:\Program Files\Java\jdk1.7.0_25"
  2. Quote it when you invoke it. Type "%JAVA_HOME%\bin" at the prompt. Of course, you'll get the "not recognized as an internal or external command, operable program or batch file" error unless you end the path with an executable (e.g. "%JAVA_HOME%\bin\javac.exe"), but you'll see that this way it complains about '"C:\Program Files\Java\jdk1.7.0_25"' rather than 'C:\Program'.

Second, you can't use environment variables in the path. You can use environment variables when you set the path at the command prompt. For example,

set PATH=%PATH%;%JAVA_HOME%

will work, but that's because %JAVA_HOME% is expanded at the command line and PATH is set to the result. If you check the value of PATH, you'll see that it ends with C:\Program Files\Java\jdk1.7.0_25, not %JAVA_HOME%.

Also, if javac.exe is in the bin subdirectory, you'll need to include that in the path, i.e. add ;C:\Program Files\Java\jdk1.7.0_25\bin to the path.

(BTW, you have %JAVA_HOME% in the path twice, and there's an extra semicolon after the second one.)

Solution 2

Yet another solution is to do this: C:\Program Files has a short name

C:\Progra~1

in windows.

so simply write Progra~1 instead of the Program Files. {added missing 'r'}

Solution 3

Is the path you are setting the JAVA_HOME environment variable in a user variable or a system variable? You cannot use user variables within system variables. So if JAVA_HOME is defined as a user variable and you are adding it to your system path that won't work.

From the output of your set command it looks like %JAVA_HOME% is not being resolved. It should show the expanded version not the one with % signs in.

Add a Path user variable and add %JAVA_HOME%\bin to that. Windows will add your user path to the end of the system path.

You should not need quotes in the JAVA_HOME variable even if it contains spaces.

Solution 4

It is very clear that , this is caused due to the blank space. Just add quotes to the phrase it foldername which contains a blank space C:\"Program Files"\Java\jdk1.7.0_25

Solution 5

Even though Adi Inbar is pretty clear on the problem, I think his workaround isn't the best solution, because it tries to patch around the original problem: spaces in the path of your JDK installation.

The best way to solve your problem is actually reinstalling JDK to a space-less path. All other workarounds will cause you headaches in the long run.

Share:
94,597

Related videos on Youtube

derekahc
Author by

derekahc

Updated on May 27, 2021

Comments

  • derekahc
    derekahc almost 3 years

    I've recently tried changing my environment variables to set paths to javac.exe (among other things). It was working fine until, all of a sudden, I started getting this error. For example, I declared a JAVA_HOME variable to be

    C:\Program Files\Java\jdk1.7.0_25

    After which, I add

    %JAVA_HOME%\bin

    to the PATH variable, but this gives me an error:

    'C:\Program' is not recognized as an internal or external command, operable command or batch file.

    This error makes it seem like it's running into problems with the space in "Program Files". This is weird, though, since it wasn't doing this for a good while, then started. Further, there are other variables with spaces in them that work just fine. I've tried deleting the variable and recreating it, putting quotes around JAVA_HOME (which goes to the correct path, but does not find javac.exe correctly)..

    Any tips on what I might do?

    This is on Windows 7.

    EDIT:

    The environment variables were set by going Control Panel > Advanced System Settings > Environment Variables. The value of the variables were set by copying the address of the folder I want through an Explorer window. I added it to the PATH environment variable by appending the address with a space between the preceding variable and a semicolon at the end, as such:

    C:\Users\Demo_User_1\AppData\Roaming\npm; %JAVA_HOME%

    where the JAVA_HOME variable is defined as such:

    C:\Program Files\Java\jdk1.7.0_25

    I test the value of the variable through a command prompt by typing %JAVA_HOME%, and that's where I get the resulting error of "'C:\Program' is not recognized..."

    The results of 'set' are as follows:

    C:\Users\Demo_User_1>set
    ALLUSERSPROFILE=C:\ProgramData
    ANDROID_HOME=C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_64-2013
    0717\sdk
    APPDATA=C:\Users\Demo_User_1\AppData\Roaming
    CommonProgramFiles=C:\Program Files\Common Files
    CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
    CommonProgramW6432=C:\Program Files\Common Files
    COMPUTERNAME=DEMO_USER_1-HP
    ComSpec=C:\Windows\system32\cmd.exe
    FP_NO_HOST_CHECK=NO
    HOMEDRIVE=C:
    HOMEPATH=\Users\Demo_User_1
    JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
    LOCALAPPDATA=C:\Users\Demo_User_1\AppData\Local
    LOGONSERVER=\\DEMO_USER_1-HP
    NUMBER_OF_PROCESSORS=4
    OnlineServices=Online Services
    OS=Windows_NT
    Path=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Clien
    t\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
    (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;
    C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
    Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\
    x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\I
    ntel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Managem
    ent Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engin
    e Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compone
    nts\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\Wir
    elessCommon\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files
     (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows
    Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\
    Tools\Binn\;C:\Program Files\nodejs\; C:\Users\Demo_User_1\Desktop\Android\adt-b
    undle-windows-x86_64-20130717\sdk/platform-tools; C:\Users\Demo_User_1\Desktop\A
    ndroid\adt-bundle-windows-x86_64-20130717\sdk\tools; %JAVA_HOME%; %ANT_HOME%/bin
    ; C:\Program Files\Java\jdk1.7.0_25\bin; C:\Users\Demo_User_1\AppData\Roaming\np
    m; "%JAVA_HOME%"; ;C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_6
    4-20130717\sdk/tools; C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x8
    6_64-20130717\sdk/platform-tools
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    PCBRAND=Pavilion
    Platform=MCD
    PROCESSOR_ARCHITECTURE=AMD64
    PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
    PROCESSOR_LEVEL=6
    PROCESSOR_REVISION=3a09
    ProgramData=C:\ProgramData
    ProgramFiles=C:\Program Files
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files
    PROMPT=$P$G
    PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
    PUBLIC=C:\Users\Public
    SESSIONNAME=Console
    SystemDrive=C:
    SystemRoot=C:\Windows
    TEMP=C:\Users\DEMO_U~1\AppData\Local\Temp
    TMP=C:\Users\DEMO_U~1\AppData\Local\Temp
    USERDOMAIN=Demo_User_1-HP
    USERNAME=Demo_User_1
    USERPROFILE=C:\Users\Demo_User_1
    VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools
    \
    windir=C:\Windows
    windows_tracing_flags=3
    windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
    
    • Adi Inbar
      Adi Inbar almost 11 years
      Please be more specific/detailed. How did you set the variable? How did you add it to the path? When/where do you get the error? Also, it would help if you post a list of the environment variables (type set at a cmd prompt and copy the results).
    • derekahc
      derekahc almost 11 years
      Your questions have been answered in an edit. Thanks!
  • Adi Inbar
    Adi Inbar almost 11 years
    I couldn't disagree more. Spaces in paths are a fact of life in Windows, and there's a space in the standard location for installed programs. Letting the "headaches" of handling spaces dictate what locations you use is what I'd call a "workaround". Learning to handle spaces properly is part of the basics of using the OS, and is a lot more valuable in the long run. Installing programs in non-standard locations just to avoid a space in the path leads to a disorganized filesystem and ultimately creates a lot more headaches. I strongly recommend against doing that.
  • kayleeFrye_onDeck
    kayleeFrye_onDeck over 7 years
    Why do you have a ` at the end of the second to last code snippet?
  • Mohammad Faisal
    Mohammad Faisal about 7 years
    @MattCraig: that could be handled with junction. where we can create a symbolic link like: junction c:\Program-Files "c:\Program Files"
  • Adi Inbar
    Adi Inbar about 7 years
    @kayleeFrye_onDeck Looks like an editing error. I probably originally had it as an inline code span, then changed it to an indented block and forgot to delete the closing backtick. I've removed it.
  • Yogen Rai
    Yogen Rai almost 7 years
    Thanks @adhg, it worked after setting up JAVA_HOME with C:\Progra~1 instead C:\Program Files\..
  • NikoNyrh
    NikoNyrh over 5 years
    FYI the same bug existed in the PySpark 2.1.1, it is fixed on later versions.
  • mavis
    mavis over 4 years
    Similarly for Program Files(x86), it is C:\Progra~2, C:\Progra~3 for ProgramData