Skip to content

Instantly share code, notes, and snippets.

@vbalien
Last active April 11, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbalien/fb2eb19c40e2146aa0da92e8cfd5255e to your computer and use it in GitHub Desktop.
Save vbalien/fb2eb19c40e2146aa0da92e8cfd5255e to your computer and use it in GitHub Desktop.
<?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