Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> popen fwrite i fread
sanchoo
post
Post #1





Grupa: Zarejestrowani
Postów: 161
Pomógł: 1
Dołączył: 11.02.2007
Skąd: Kraków

Ostrzeżenie: (0%)
-----


  1. <?php
  2.  
  3.    $text = '';
  4.    $error = '';
  5.    $descriptorspec = array(
  6.        0 => array("pipe", "r"),  // stdin
  7.        1 => array("pipe", "w"),  // stdout
  8.        2 => array("pipe", "w")   // stderr questionmark.gif instead of a file
  9.        );
  10.        
  11.        
  12.    $command = 'ls  2>&1';
  13.    $process = proc_open($command, $descriptorspec, $pipes);
  14.    if (is_resource($process)) {
  15.        fwrite($pipes[0], 'ls -all /');
  16.        fclose($pipes[0]);
  17.        while($s= fgets($pipes[1], 1024)) {
  18.          // read from the pipe
  19.          $text .= $s;
  20.        }
  21.        fclose($pipes[1]);
  22.        // optional:
  23.        while($s= fgets($pipes[2], 1024)) {
  24.          $error .= $s . "\n";
  25.        }
  26.        fclose($pipes[2]);
  27.    }
  28.          
  29.    var_dump($text);
  30.  
  31.  
  32.  
  33. ?>


Nie jestem pewny czy do końca rozumiem popen. Tu jest przukład zastosowanie będzie inne ale go uprosiciłem do tego co potrzebuje zrozumieć. Po napsianu do stdin "fwrite($pipes[0], 'ls -all /');" jak mam odczytac ten wynik?? w tej chwili zwraca mi tylko to co zostalo napisane w "$command "
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 10:57