$file='./process_list.txt';
$command="ps awx";
$process_list=shell_exec($command);
file_put_contents($file,$process_list);
$handle = fopen ($file, "r");
if($handle){
while (!feof ($handle)){
$processRow = fgets($handle, 4096);
/*do somethings here*/
}
fclose ($handle);
}
以上做法是将shell_exec返回的内容存到文件里,再打开文件,一行一行地读。
觉得这样做比较麻烦,可以不用文件做介质吗?想用换行符分开:
$rows=explode("\\r\\n",$process_list);未果!