当前位置: 首页 > 知识库问答 >
问题:

Windows CMD. exe"系统找不到指定的路径。"

姚俊贤
2023-03-14

1)当我打开新的CMD(Win R=

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
The system cannot find the path specified.

C:\Users\ViliamKopecky>

2) 当我执行一些命令时,如cmd/C dir(或cmd/C php-v)或其他命令(第2行)

C:\Users\ViliamKopecky>cmd /C dir
The system cannot find the path specified.
 Volume in drive C is Windows7_OS
 Volume Serial Number is 8230-1246
...

C:\Windows\System32>cmd /C php -v
The system cannot find the path specified.
PHP 5.4.8 (cli) (built: Oct 16 2012 22:30:23)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

3)(最讨厌的)当我运行exec函数从PHP或Node.js或可能任何脚本语言。(

1) 当我直接从cmd(或mingw,…)执行命令时

C:\Users\ViliamKopecky>dir
 Volume in drive C is Windows7_OS
 Volume Serial Number is 8230-1246

 Directory of C:\Users\ViliamKopecky

让我们从cmd的简单命令开始。

php-r“exec('dir',$stdout,$stderr);print(内爆(\”\n\“,$stdout),$stderr);”

结果如下(目录测试为空-这是正确的):

E:\test>php -r "exec('dir', $stdout, $stderr); print(implode(\"\n\", $stdout), $stderr);"
The system cannot find the path specified.
 Volume in drive E is www
 Volume Serial Number is 0C99-95EC

 Directory of E:\test

09.11.2012  22:42    <DIR>          .
09.11.2012  22:42    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  13 495 296 000 bytes free
int(1)

这表明从php正确执行了dir命令。唯一错误的是第二行-系统无法找到指定的路径。-这不应该存在。

此消息由exec从PHP(以及Node.js)输出为require('child\u process')。exec(“dir”,function(err,stdout,stderr){console.log(stderr)}

当我直接从cmd(或mingw等)执行命令时,它会正确执行,没有消息。环境变量路径似乎正常。问题只是通过exec函数从脚本环境执行。

如何摆脱那个烦人的信息?谢谢


共有3个答案

柴岳
2023-03-14

此消息可能表示环境变量path中不存在路径。

以下PowerShell命令将打印丢失的路径。

($env:path).Trim(";").Split(";") | ? {-not (test-path $_)}

例如

> ($env:path).Trim(";").Split(";") | ? {-not (test-path $_)}
C:\Program Files\CMake\bin
C:\Program Files\SDCC\bin
C:\Users\wjbr\AppData\Local\Programs\Microsoft VS Code\bin

参考文献

  • http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/
  • https://javarevisited.blogspot.com/2017/01/the-system-cannot-find-path-specified-error-in-command-prompt.html
葛雨华
2023-03-14

这实际上看起来像是PHP的启动错误,而不是您的代码。做

php-r“echo 1;”

是否也抛出相同的错误?如果是的话,请使用php。ini文件或包含的路径可能不正确。

php-i

应该给你更多信息。

王君墨
2023-03-14

问题是某些程序已设置为自动运行时,你运行cmd.exe.在我的情况下,它是ANSICON被安装...然后我移动文件没有正确卸载。

我在这篇博文中找到了一个解决方案:

http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/

简短的版本是

HKCU \软件\ Microsoft \命令处理器\自动运行

并清除该值。

 类似资料:
  • 我得到以下Tomcat错误: 发布到Tomcat v8.5 Server atlocalhost...遇到问题。发布失败并出现多个错误。 细节: 发布失败,出现多个错误 找不到文件:C:\Users…\HerramentationLogica\target\m2e wtp\web资源\META-INF\MANIFEST.MF。 未找到文件:C:\Users…\HerramentationLogic

  • 我已经编写了一个基本的jsp代码,用于存储和检索数据库中的数据。在此之前,我正在检查用户验证。 当我点击提交按钮时,它将重定向到我的jsp页面。 我已经写了一个数据库。属性文件分开。 当我给出了读取属性文件的完整路径时。,程序执行正常。(这不是像下面这样硬代码的最佳方式)。 FileInputStream in=new FileInputStream("C:\Program Files\Apach

  • 我以管理员权限运行命令提示符卸载我电脑上的Ananconda,在此过程之后,我重新打开cmd,发现cmd开头有一行“系统找不到指定的路径”。 我可以保证我的cmd以前没有这一行,我该如何修复它?这是我应该注意的严重错误吗? 非常感谢。 “系统找不到指定的路径。”

  • 按照http://maven.apache.org/download.cgi上的所有说明操作 Java版本:1.7.0_03,供应商:Oracle Corporation Java Home:C:\程序文件\Java\jdk1.7.0_03\jre 默认区域设置:en_US,平台编码:Cp1252 操作系统名称:“Windows 7”,版本:“6.1”,arch:“AMD64”,系列:“Windo