Last active
April 11, 2016 13:46
-
-
Save vbalien/fb2eb19c40e2146aa0da92e8cfd5255e to your computer and use it in GitHub Desktop.
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 | |
$descriptorspec = array( | |
0 => array("pipe", "r"), // stdin 스트림 | |
1 => array("pipe", "w"), // stdout 스트림 | |
2 => array("file", "/tmp/error-output.txt", "a") // stderr 스트림 -> 파일로 씀 | |
); | |
$cwd = '/tmp'; // 실행할 디렉터리 | |
// $env = array('some_option' => 'aeiou'); // 변수 설정 | |
// 실행파일 실행 | |
$process = proc_open('a.out', $descriptorspec, $pipes, $cwd, $env); | |
if (is_resource($process)) { | |
fwrite($pipes[0], '10'); // stdin에 10 쓰기 | |
fclose($pipes[0]); // stdin닫기 | |
echo stream_get_contents($pipes[1]); // stdout읽어서 echo | |
fclose($pipes[1]); // stdout닫기 | |
$return_value = proc_close($process); // 프로세스 닫기 | |
echo "command returned $return_value\n"; // main함수 리턴값 리턴 (정상 종료는 0) | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment