Created
June 3, 2012 22:28
-
-
Save sbisbee/2865231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# foo.plx | |
# This is what the other file sends its contents to. | |
open(FILE, ">/tmp/foo"); | |
print FILE "----start----\n"; | |
# Write all of the piped input to the FILE | |
while(<STDIN>) { | |
print FILE $_; | |
} | |
print FILE "----end----"; | |
close(FILE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Create the process, naming the in/out pipes. | |
$proc = proc_open( | |
'/home/sbisbee/src/foo.plx', | |
array( array('pipe', 'r'), array('pipe', 'w') ), | |
$pipes | |
); | |
if(is_resource($proc)) { | |
// Get this file's contents ($_SERVER['SCRIPT_FILENAME']) and write them | |
fwrite($pipes[0], file_get_contents($_SERVER['SCRIPT_FILENAME'])); | |
fclose($pipes[0]); | |
// See what the script returns to us (if anything) | |
echo '<div>' . stream_get_contents($pipes[1]) . '</div>'; | |
// Always make sure you clean up your procs before terminating. | |
fclose($pipes[1]); | |
echo 'command returned ' . proc_close($proc); | |
} | |
else { | |
echo 'could not open the process'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment