summaryrefslogtreecommitdiff
path: root/inc/io.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/io.php')
-rw-r--r--inc/io.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/inc/io.php b/inc/io.php
index 559f3febc..034ac650e 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -529,7 +529,7 @@ function io_rename($from,$to){
/**
- * Runs an external command and returns it's output as string
+ * Runs an external command and returns its output as string
*
* @author Harry Brueckner <harry_b@eml.cc>
* @author Andreas Gohr <andi@splitbrain.org>
@@ -547,6 +547,27 @@ function io_runcmd($cmd){
}
/**
+ * Runs an external command with input and output pipes.
+ * Returns the exit code from the process.
+ *
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+function io_exec($cmd, $input, &$output){
+ $descspec = array(
+ 0=>array("pipe","r"),
+ 1=>array("pipe","w"),
+ 2=>array("pipe","w"));
+ $ph = proc_open($cmd, $descspec, $pipes);
+ if(!$ph) return -1;
+ fclose($pipes[2]); // ignore stderr
+ fwrite($pipes[0], $input);
+ fclose($pipes[0]);
+ $output = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+ return proc_close($ph);
+}
+
+/**
* Search a file for matching lines
*
* This is probably not faster than file()+preg_grep() but less