通过将 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)(最烦人的)当我exec
从 PHP 或 Node.js 或任何脚本语言运行函数时。(可能是从内部运行的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)
这表明该命令dir
已从 php 正确执行。唯一错误的是第二行 -系统找不到指定的路径。- 那不应该在那里。
此消息由 exec 从PHP输出(也从Node.js as输出require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});
)
当我直接从 cmd(或 mingw 等)执行命令时,它会在没有消息的情况下正确执行。环境变量 PATH 似乎没问题。问题只是通过exec
函数从脚本环境执行。
如何摆脱那个烦人的消息?谢谢