0

I want to write output of command in to php file.But when I open file only one line of output is written.

  $myfile = fopen("status1.txt", "a+"); 
  $cmd="asterisk -rx 'sip show peers'|greo OK";

  $test1=system($cmd);
  fwrite($myfile, $test1);
  fclose($myfile);

OUTPUT is

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  

But In file only first line is written

singhakash
  • 7,891
  • 6
  • 31
  • 65
soni8010
  • 385
  • 1
  • 6
  • 19

1 Answers1

0

You may try to use the exec function instead of system

e.g.

exec($cmd,scanme);
$scanme = implode("\n",$scanme);

exec ( string $command [, array &$output [, int &$return_var ]] )

Your case:

  $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);
Tarun Upadhyay
  • 724
  • 2
  • 7
  • 16