Created
February 23, 2015 20:45
-
-
Save xendk/1d5398a18fdc28f8deb2 to your computer and use it in GitHub Desktop.
Challenge
This file contains 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 | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Symfony\Component\Process\ProcessBuilder; | |
// This doesn't work. The stream_select inside Process doesn't see any new | |
// input. We want to create a stream that can be written to asyncroniouly. | |
$inputStream = fopen("php://temp/", 'r+'); | |
$processBuilder = new ProcessBuilder(array('cat')); | |
$processBuilder->setInput($inputStream); | |
$process = $processBuilder->getProcess(); | |
$process->start(); | |
// Doesn't have to be fwrite. | |
fwrite($inputStream, "We have a winner!\n\n"); | |
fclose($inputStream); | |
$exitCode = $process->wait(); | |
$output = $process->getOutput(); | |
if (empty($output)) { | |
echo "Sorry, no dice.\n\n"; | |
} else { | |
echo $output; | |
} |
This file contains 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
{ | |
"require": { | |
"php": ">=5.4.0", | |
"symfony/process": "~2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't looke like Process and/or UnixPipes support proc_open() with a file resource.