
proc_open 함수를 사용하여 프로세스를 생성하고 통신을 할 때, 오류 메시지를 출력하기 위해서는 다음과 같은 방법을 사용할 수 있습니다.
1. `$descriptorspec` 배열에 `2 => array("pipe", "w")`를 추가하여 오류 메시지를 읽을 수 있도록 합니다.
2. 오류 메시지를 읽기 위해 `stream_get_contents($pipes[2]);`를 사용합니다.
3. 오류 메시지를 출력하기 위해 `echo $output;`를 사용합니다.
예제를 보시면 다음과 같습니다.
#hostingforum.kr
php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$process = proc_open('ls -l', $descriptorspec, $pipes);
if (is_resource($process)) {
$output = stream_get_contents($pipes[1]);
$error = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
echo $output;
echo $error;
}
이 예제에서는 `$pipes[2]`를 사용하여 오류 메시지를 읽고 출력합니다.
2025-04-23 13:10