系统换平台时,在调试中发现cmd命令无法使用,根据多次的经验,一直以为是 cmd.exe的权限问题,
当吧所有的权限都给足后发现还是无法执行cmd命令,
function my_exec($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]);fclose($pipes[1]);
$stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);
$rtn=proc_close($proc);
return array('stdout'=>$stdout,
'stderr'=>$stderr,
'return'=>$rtn
);
}
$str = " /opt/rpm/bin/rpm -bb --target i686--linux /tmp/test.spec"; (这里换成你cmd命令执行一下)
var_export(my_exec($str));
这个方法我今天也是过了,真的可以用的