通过恢复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
函数时(这些可能作为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);"
结果如下(目录test为空-这是正确的):
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
。唯一错误的是第二行 - The system cannot find the path specified. - 它不应该出现。
此消息由从PHP(以及从Node.js作为require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});
)中的 exec 输出。
当我直接从 cmd (或 mingw 等) 执行命令时,它可以正确执行而没有出现此消息。环境变量 PATH 似乎没问题。问题只是通过 exec
函数从脚本环境执行命令。
如何消除这个烦人的消息?谢谢。
system
和shell_exec
都会做同样糟糕的事情。 - ViliamKopecky