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

时间:2012-11-09 22:01:49

标签: php windows cmd system exec

通过将Windows还原到以前的状态

来解决

消息(系统找不到指定的路径。)显示...

1)当我打开新的CMD(Win + R => cmd)时。它从介绍开始。 (第3行)

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)(最烦人的)当我从PHP或Node.js运行exec函数或者可能是任何脚本lang时。 (可能从内部以cmd /C <command>

运行

消息未显示......

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(implode(\"\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)

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

此消息由exec从 PHP (以及 Node.js 输出为require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});)输出

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

如何摆脱烦人的消息?谢谢

4 个答案:

答案 0 :(得分:35)

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

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

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

简短版本是找

HKCU \ Software \ Microsoft \ Command Processor \ AutoRun

并清除价值。

答案 1 :(得分:0)

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

php -r "echo 1;"

也会抛出同样的错误?如果是这样,您的php.ini文件或包含可能会被错误地修改。

php -i

应该为您提供更多信息。

答案 2 :(得分:0)

我想你应该尝试一下!我有同样的问题,并解决了这个问题:

ok type:cd \ windows \ system32 之后你会看到:System32 /: 输入您想要的内容(例如:ipconfig): System32:ipconfig 那应该这样做! :)

答案 3 :(得分:0)

此消息可能意味着 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

参考资料

相关问题