getIterator() public method

Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
public getIterator ( integer $flags ) : Generator
$flags integer A bit field of Process::ITER_* flags
return Generator
示例#1
0
 public function testNonBlockingNorClearingIteratorOutput()
 {
     $input = new InputStream();
     $process = new Process(self::$phpBin . ' -r ' . escapeshellarg('fwrite(STDOUT, fread(STDIN, 3));'));
     $process->setInput($input);
     $process->start();
     $output = array();
     foreach ($process->getIterator(false, false) as $type => $data) {
         $output[] = array($type, $data);
         break;
     }
     $expectedOutput = array(array($process::OUT, ''));
     $this->assertSame($expectedOutput, $output);
     $input->write(123);
     foreach ($process->getIterator(false, false) as $type => $data) {
         if ('' !== $data) {
             $output[] = array($type, $data);
         }
     }
     $this->assertSame('123', $process->getOutput());
     $this->assertFalse($process->isRunning());
     $expectedOutput = array(array($process::OUT, ''), array($process::OUT, '123'));
     $this->assertSame($expectedOutput, $output);
 }