Vil*_*cky 17 php windows cmd system exec
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>
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
3)(最烦人的)当我exec从PHP或Node.js或任何脚本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
Run Code Online (Sandbox Code Playgroud)
让我们从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)
Run Code Online (Sandbox Code Playgroud)
这表明该命令dir已从php正确执行.唯一错误的是第二行 - 系统找不到指定的路径. - 那不应该在那里.
此消息是由EXEC输出从PHP(并且还从Node.js的如require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});)
当我从cmd(或mingw等)执行命令时,它正确执行而没有消息.环境变量PATH似乎没问题.问题只是通过exec函数从脚本环境执行.
如何摆脱那令人讨厌的消息?谢谢
s3v*_*3v1 40
问题是当您运行cmd.exe时某些程序已设置为自动运行.在我的情况下,安装了ANSICON ...然后我移动了文件而没有正确卸载.
我在这篇博文中找到了一个解决方案:
http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/
简短的版本是找到
HKCU\Software\Microsoft\Command Processor\AutoRun
并清除价值.