この小さなバグを修正する必要があります。まず、小さな事実について話しましょう。WindowsのCLIでは、エスケープしない限り、パスにスペースを入れてプログラムを実行することはできません。
C:\>a b/c.bat
'a' is not recognized as an internal or external command,
operable program or batch file.
C:\>"a b/c.bat"
C:\>
PHPでproc_open...proc_closeを使用してプロセス(プログラム)を実行しています。例:
function _pipeExec($cmd,$input=''){
$proc=proc_open($cmd,array(0=>array('pipe','r'),
1=>array('pipe','w'),2=>array('pipe','w')),$pipes);
fwrite($pipes[0],$input);
fclose($pipes[0]);
$stdout=stream_get_contents($pipes[1]); // max execusion time exceeded ssue
fclose($pipes[1]);
$stderr=stream_get_contents($pipes[2]);
fclose($pipes[2]);
$rtn=proc_close($proc);
return array(
'stdout'=>$stdout,
'stderr'=>$stderr,
'return'=>(int)$rtn
);
}
// example 1
_pipeExec('C:\\a b\\c.bat -switch');
// example 2
_pipeExec('"C:\\a b\\c.bat" -switch');
// example 3 (sounds stupid but I had to try)
_pipeExec('""C:\\a b\\c.bat"" -switch');
例1
- 結果:1
- STDERR:'C:\ a'は、内部または外部コマンド、操作可能なプログラム、またはバッチファイルとして認識されません。
- STDOUT:
例2
- 結果:1
- STDERR:'C:\ a'は、内部または外部コマンド、操作可能なプログラム、またはバッチファイルとして認識されません。
- STDOUT:
例3
- 結果:1
- STDERR:ファイル名、ディレクトリ名、またはボリュームラベルの構文が正しくありません。
- STDOUT:
ご覧のとおり、どちらの場合(二重引用符であるかどうかに関係なく)、コードは失敗します。それは私ですか、それとも何かが足りないのですか?