Created
July 20, 2011 09:37
-
-
Save pierrejoye/1094669 to your computer and use it in GitHub Desktop.
proc_open example
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 | |
| $cmd = "C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe"; | |
| $parts = array( | |
| '-jar' => 'G:\\test\\yuic\\build\\yuicompressor-2.4.6.jar', | |
| '--type' => 'css', | |
| '--charset' => 'UTF-8', | |
| 'H:\\projects\\assetic\\assetic\\tests\\Assetic\\Test\\Filter\\fixtures\\cssmin\\fonts.css -o g:\\temp\\test.css', | |
| '-o' => 'g:\\temp\\test.css', | |
| ); | |
| $args = ''; | |
| foreach ($parts as $k => $part) { | |
| if (is_string($k)) { | |
| $args .= ' ' . escapeshellarg($k) . ' ' . escapeshellarg($part); | |
| } else { | |
| $args .= ' ' . escapeshellarg($part); | |
| } | |
| } | |
| $process_cmd = '"' . $cmd . '"' . ' ' . $args; | |
| $env = NULL; | |
| $options = array('bypass_shell' => true); | |
| $cwd = 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") // stderr is a file to write to | |
| ); | |
| $process = proc_open($process_cmd, $descriptorspec, $pipes, $cwd, $env, $options); | |
| if (is_resource($process)) { | |
| echo stream_get_contents($pipes[1]); | |
| fclose($pipes[1]); | |
| // It is important that you close any pipes before calling | |
| // proc_close in order to avoid a deadlock | |
| $return_value = proc_close($process); | |
| echo "command returned $return_value\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment