<?php
class Shell {
/* Define constants */
// This can be set to null for unrestricted buffer space
const MAX_OUTPUT_BUFFER = 256;
/* Define static properties */
private static $output_buffer = array();
/**
* Execute a command, add the output to the buffer stack
* @return Int Command return status
* @param $command String
*/
static function exec($command) {
@exec($command, $tmp_ob, $status);
Shell::$output_buffer = array_merge((array) Shell::$output_buffer, (array) $tmp_ob);
while(count(Shell::$output_buffer) > Shell::MAX_OUTPUT_BUFFER && Shell::MAX_OUTPUT_BUFFER != null) {
array_shift(Shell::$output_buffer);
}
return (int) $status;
}
/**
* Flush the buffer stack
* @return null
*/
static function flush() {
Shell::$output_buffer = array();
}
/**
* Print the buffer stack
* @return null
*/
static function output() {
foreach(Shell::$output_buffer as $output_line) {
printf("%s\n", $output_line);
}
}
}
?>
Comments