summaryrefslogtreecommitdiff
path: root/inc/io.php
diff options
context:
space:
mode:
authorTom N Harris <tnharris@whoopdedo.org>2010-11-20 14:29:13 -0500
committerTom N Harris <tnharris@whoopdedo.org>2010-11-20 14:29:13 -0500
commit3c4b38902b6f6d32222611b22087d5d41d20de6e (patch)
tree3d28bbaa015e10283050b6512a4f49e53323b8fc /inc/io.php
parent4753bcc0e2fd9417e885e128e8c9ab4bfc566c32 (diff)
parent420edfd639fb3d0a0f6a2504ecb2f8f6b68be1f7 (diff)
downloadrpg-3c4b38902b6f6d32222611b22087d5d41d20de6e.tar.gz
rpg-3c4b38902b6f6d32222611b22087d5d41d20de6e.tar.bz2
Merge branch 'tokenizer-rewrite' into michitux
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 1d69dabc9..a0be00da3 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