1 개요[ | ]
- PHP proc_open()
- 명령어를 실행하고 입출력에 대한 파일 포인터를 여는 PHP 함수
2 예제 1[ | ]
PHP
Copy
<?php
$desc = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
);
$process = proc_open("md5sum", $desc, $pipes);
if (is_resyntaxhighlight($process)) {
$input = 'hello';
fwrite($pipes[0], $input);
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
$exit_status = proc_close($process);
echo "input: $input\n";
echo "output: $output\n";
echo "exit status: $exit_status\n";
}
# input: hello
# output: 5d41402abc4b2a76b9719d911017c592 -
#
# exit status: 0
3 예제 2[ | ]
PHP
Copy
<?php
$desc = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
);
$process = proc_open("not-exist-command", $desc, $pipes);
if (is_resyntaxhighlight($process)) {
$input = 'hello';
fwrite($pipes[0], $input);
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
$exit_status = proc_close($process);
echo "input: $input\n";
echo "output: $output\n";
echo "exit status: $exit_status\n";
}
Console
Copy
root@zetawiki:~# php proc_open_test1.php
input: hello
output:
exit status: 127
Console
Copy
root@zetawiki:~# cat /tmp/error-output.txt
sh: 1: not-exist-command: not found
4 같이 보기[ | ]
- PHP proc_close()
- PHP popen() - 파일 포인터 열기
- PHP exec() - 외부 프로그램 실행
- PHP system() - 외부 프로그램 실행하고 출력값 표시
- PHP passthru() - 외부 프로그램 실행하고 출력값 그대로 표시
- PHP stream_select()
5 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- PHP (8)
PHP 파일 다운로드 구현 2 (한글 파일명 지원) ― …PHP에서 오라클 DB 사용 ― YoWuPHP 파일 업로드 구현 ― 일리단사오육칠PHP 파일 업로드 구현 ― JmnotePHP 파일 다운로드 구현 2 (한글 파일명 지원) ― AnmkstLib my.php ― 신정섭Lib my.php ― Jmnote로또번호 생성 ―Pinkcrimson