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>
cmd /C dir
2) (または何か)のようなコマンドを実行したとき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);"
結果は次のようになります(ディレクトリテストは空です-これは正しいです):
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から正しく実行されたことを示しています。間違っているのは2行目だけです-システムは指定されたパスを見つけることができません。-それはそこにあるべきではありません。
このメッセージは、 PHPから(およびNode.jsからrequire('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});
)execによって出力されます。
cmd(またはmingwなど)から直接コマンドを実行すると、メッセージなしで正しく実行されます。環境変数PATHは問題ないようです。問題は、スクリプト環境からexec
関数を介して実行することです。
その迷惑なメッセージを取り除く方法は?ありがとう