我想在php文件中写入命令的输出。但是当我打开文件时,只输出一行。
$myfile = fopen("status1.txt", "a+");
$cmd="asterisk -rx 'sip show peers'|greo OK";
$test1=system($cmd);
fwrite($myfile, $test1);
fclose($myfile);
输出1004 /1004 (Unspecified) D 0 OK
1005 /1005 (Unspecified) D N 0 OK
1006 /1006 (Unspecified) D N 0 OK
2501 /2501 (Unspecified) D 0 OK
2502 /2502 (Unspecified) D a 0 OK
2503 /2503 (Unspecified) D a 0 OK
2504 /2504 (Unspecified) D 0 OK
但是在文件中只有第一行写
您可以尝试使用exec函数而不是system
。
exec($cmd,scanme);
$scanme = implode("n",$scanme);
exec (string $command [, array &$output [, int &$return_var]])
你的情况:
$myfile = fopen("status1.txt", "a+");
$cmd="asterisk -rx 'sip show peers'|greo OK";
exec($cmd,$test1);
$test1 = implode("n",$test1);
fwrite($myfile, $test1);
fclose($myfile);