0
$out = shell_exec('powershell -command "& {Get-WmiObject win32_Process | where-object {($_.CommandLine -like \"*php*\") } | Select-Object ProcessId,CommandLine,\"MMxDelimiter\" | Format-List}" < NULL');

foreach (explode("MMxDelimiter :",$out) as $Row) {
    preg_match_all("/ProcessId[^:]+:[^0-9]+([0-9]+)[^a-z]*CommandLine[^:]+:(.+)/is",$Row,$OutPut);
    if (trim($OutPut[1][0]) != "") {
        $Files[] = array("ProcessId"=>$OutPut[1][0],"Command"=>preg_replace("/[\n][ ]+/","",$OutPut[2][0]));
    }
}
print_r($Files);

このコードは、Power Shell を介して動作している php ファイルを表示します。これは win7 でうまく動作していますが、< NULLパラメーターが原因で win server 2008 でエラーが発生します。

誰でもこの問題を解決するにはどうすればよいか教えてください

4

1 に答える 1

0
$out = shell_exec('powershell -command "& {Get-WmiObject win32_Process | where-object {($_.CommandLine -like \"*php*\") } | Select-Object ProcessId,CommandLine,\"MMxDelimiter\" | Format-List}" < '.__FILE__);

foreach (explode("MMxDelimiter :",$out) as $Row) {
    preg_match_all("/ProcessId[^:]+:[^0-9]+([0-9]+)[^a-z]*CommandLine[^:]+:(.+)/is",$Row,$OutPut);
    if (trim($OutPut[1][0]) != "") {
        $Files[] = array("ProcessId"=>$OutPut[1][0],"Command"=>preg_replace("/[\n][ ]+/","",$OutPut[2][0]));
    }
}
print_r($Files);

私は< NULL実際のファイルパスを変更した < __FILE__ ので、それは最善の解決策ではありませんが、機能しています!!!

于 2013-08-23T07:03:42.383 に答える