windows 'C:\Program' 无法识别错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17845809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:45:20  来源:igfitidea点击:

'C:\Program' is not recognized error

windowscmdenvironment-variables

提问by derekahc

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

我最近尝试更改我的环境变量以设置 javac.exe 的路径(除其他外)。它工作正常,直到突然间,我开始收到此错误。例如,我声明了一个 JAVA_HOME 变量为

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

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

After which, I add

之后,我添加

%JAVA_HOME%\bin

%JAVA_HOME%\bin

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

到 PATH 变量,但这给了我一个错误:

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

'C:\Program' 不是内部或外部命令,也不是可操作的命令或批处理文件。

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

这个错误使它看起来像是遇到了“程序文件”中的空间问题。不过,这很奇怪,因为它已经有一段时间没有这样做了,然后就开始了。此外,还有其他带有空格的变量可以正常工作。我试过删除变量并重新创建它,在 JAVA_HOME 周围加上引号(它转到正确的路径,但没有正确找到 javac.exe)。

Any tips on what I might do?

关于我可以做什么的任何提示?

This is on Windows 7.

这是在 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:

通过转到控制面板 > 高级系统设置 > 环境变量来设置环境变量。通过通过资源管理器窗口复制我想要的文件夹的地址来设置变量的值。我通过在前面的变量和末尾的分号之间附加一个空格来将它添加到 PATH 环境变量中,如下所示:

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

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

where the JAVA_HOME variable is defined as such:

其中 JAVA_HOME 变量定义如下:

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

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

我通过命令提示符输入 %JAVA_HOME% 来测试变量的值,这就是我得到“'C:\Program' 无法识别...”的结果错误的地方

The results of 'set' are as follows:

'set'的结果如下:

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.0\bin\
x86;C:\Program Files (x86)\Intel\OpenCL SDK.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.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server0\
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

回答by adhg

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

另一种解决方案是这样做:C:\Program Files有一个短名称

C:\Progra~1

C:\程序~1

in windows.

在窗户里。

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

所以只需编写 Progra~1 而不是 Program Files。{添加缺少的'r'}

回答by Adi Inbar

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.

首先,你得到的原因'C:\Program' is not recognized...当然是因为它包含空格。您在 PATH 环境变量中引用它这一事实与在提示符下解释%JAVA_HOME% 的方式无关。你有两个选择。

  1. Quote it when you define the variable, i.e. set JAVA_HOMEto "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'.
  1. 定义变量时引用它,即设置JAVA_HOME"C:\Program Files\Java\jdk1.7.0_25"
  2. 当你调用它时引用它。键入"%JAVA_HOME%\bin"在提示符下。当然,除非您以可执行文件(例如"%JAVA_HOME%\bin\javac.exe")结束路径,否则您会收到“未识别为内部或外部命令、可运行的程序或批处理文件”错误,但您会看到它以这种方式抱怨“” C:\Program Files\Java\jdk1.7.0_25"'而不是'C:\Program'

Second, you can't use environment variables in the path. You canuse 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 PATHis 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%.

会起作用,但那是因为%JAVA_HOME%在命令行中展开并且PATH设置为结果。如果您检查PATH的值,您会看到它以C:\Program Files\Java\jdk1.7.0_25 结尾,而不是%JAVA_HOME%

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

此外,如果javac.exe位于bin子目录中,则需要将其包含在路径中,即添加;C:\Program Files\Java\jdk1.7.0_25\bin到路径中。

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

(顺便说一句,您在路径中有两次%JAVA_HOME%,并且在第二次之后有一个额外的分号。)

回答by andrea

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.

您在用户变量或系统变量中设置 JAVA_HOME 环境变量的路径是?您不能在系统变量中使用用户变量。因此,如果 JAVA_HOME 被定义为用户变量并且您将其添加到您的系统路径中,则该路径将不起作用。

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.

从 set 命令的输出看来 %JAVA_HOME% 没有得到解决。它应该显示扩展版本而不是带有 % 登录的版本。

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.

添加 Path 用户变量并将 %JAVA_HOME%\bin 添加到其中。Windows 会将您的用户路径添加到系统路径的末尾。

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

JAVA_HOME 变量中不需要引号,即使它包含空格。

回答by Ronak

just add cd before adding the location eg: instead of

只需在添加位置之前添加 cd 例如:而不是

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

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

use

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

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

this helped me.

这对我有帮助。

回答by DigCamara

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.

尽管 Adi Inbar 对这个问题非常清楚,但我认为他的解决方法不是最好的解决方案,因为它试图解决原始问题:JDK 安装路径中的空格。

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.

解决问题的最佳方法实际上是将 JDK 重新安装到无空间的路径。从长远来看,所有其他解决方法都会让您头疼。

回答by Jag

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

如果您使用的是 Windows 10,请使用浏览文件夹而不是编辑文本。我遇到了类似的问题,使用上述方法解决了这个问题。

Hope this helps!

希望这可以帮助!

enter image description here

在此处输入图片说明

回答by Shubham gupta

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

很明显,这是由空格引起的。只需在包含空格 C:\"Program Files"\Java\jdk1.7.0_25 的短语 it foldername 中添加引号

回答by Mohit Varshney

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.

重新安装 Java 并将其安装目录从 C:\Program Files\Java\jdk 更改为 C:\Java\jdk 中的某个位置。避免在安装中使用 Program Files 文件夹,因为“Program”和“Files”之间的空间会产生问题。

Thanks!!

谢谢!!