'C:\Program' is not recognized error
Asked Answered
T

8

23

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
Thermotaxis answered 24/7, 2013 at 22:20 Comment(2)
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).Admissible
Your questions have been answered in an edit. Thanks!Thermotaxis
A
26

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.)

Admissible answered 25/7, 2013 at 18:51 Comment(3)
Why do you have a ` at the end of the second to last code snippet?Rainarainah
@Rainarainah 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.Admissible
FYI the same bug existed in the PySpark 2.1.1, it is fixed on later versions.Ringsmuth
S
43

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'}

Schooner answered 20/11, 2013 at 17:43 Comment(3)
@MattCraig: that could be handled with junction. where we can create a symbolic link like: junction c:\Program-Files "c:\Program Files"Xerophyte
Thanks @adhg, it worked after setting up JAVA_HOME with C:\Progra~1 instead C:\Program Files\..Trehalose
Similarly for Program Files(x86), it is C:\Progra~2, C:\Progra~3 for ProgramDataSherfield
A
26

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.)

Admissible answered 25/7, 2013 at 18:51 Comment(3)
Why do you have a ` at the end of the second to last code snippet?Rainarainah
@Rainarainah 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.Admissible
FYI the same bug existed in the PySpark 2.1.1, it is fixed on later versions.Ringsmuth
F
2

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.

Fecal answered 13/5, 2014 at 11:14 Comment(0)
C
1

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.

Craal answered 25/7, 2013 at 19:26 Comment(1)
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.Admissible
R
1

just add cd before adding the location eg: instead of

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

use

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

this helped me.

Rodomontade answered 20/4, 2016 at 11:59 Comment(0)
T
0

if you are Windows 10, Use Browse Folder rather than Edit text. I had similar issue and this got resolved using above method.

Hope this helps!

enter image description here

Tevis answered 19/2, 2019 at 0:25 Comment(0)
J
0

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

Juieta answered 18/2, 2020 at 4:50 Comment(0)
E
0

Reinstall Java and change its installation directory from C:\Program Files\Java\jdk to somewhere in C:\Java\jdk. Avoid to use Program Files folder in installation as space between 'Program' and 'Files' creates problem.

Thanks!!

Exciter answered 26/2, 2020 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.