PHP Classes

File: helper/exec.php

Recommend this page to a friend!
  Classes of Alexey Starikov   PHP Helper Class   helper/exec.php   Download  
File: helper/exec.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Helper Class
Call helper functions that are loaded dynamically
Author: By
Last change:
Date: 5 years ago
Size: 705 bytes
 

Contents

Class file image Download
<?php
# exec
return function ($cmd,$path='',$env=null) {
   
$descriptorspec = array(
       
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
       
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
       
2 => array("pipe", "w"),// 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
   
);
   
$process = proc_open($cmd, $descriptorspec, $pipes, $path, $env );
    if (
is_resource($process)){
       
$ret= stream_get_contents($pipes[1]);
// echo stream_get_contents($pipes[2]); # errors
       
fclose($pipes[0]);
       
fclose($pipes[1]);
       
fclose($pipes[2]);
    return
$ret;

    }else return
false;
}
?>