Q:

Running script and executing PHP for output

I'm looking to run a program, and for every output line it generates, execute a PHP script and pass the line content to it. 
I know, pretty hard to understand.  Here's an example:
Execute script -> script outputs 'Initializing script on 127.0.0.1'.  Now it needs to execute a command like php5 input.php 'Initializing script on 127.0.0.1'. 
Is this doable?  If so, how would I go about doing this? 
Edit: to clarify; I basically want command > log.txt but in stead of writing the output to that file, writing it to a PHP script as an argument

A:

PHP is an interpreter much like Bash, Python, etc, so you can do "normal" scripting with it.   For example:
#! /usr/bin/php5

<? php

echo "Hello, world!\n";

while($line = fgets(STDIN)) {
  echo "> " .  $line;
}

? >

Mark the file as executable, then run:
$ /program/that/generates/lines | /path/to/your/php/script

However, contrary to your original question, it sounds to me like you actually want to use JavaScript and possibly AJAX for web purposes.   Sane web applications will have the said script run in the background and safely write the results to a file or stream, using AJAX to read it and update the information on the current page.