php 스크립트와 외부 프로그램이 서로 통신하려면...

dltkddyd의 이미지

스크립트로 만든 pipe1.php 파일은 외부 프로그램 cpipe1을 실행하고 cpipe1이 출력한 결과를 파이프를 통해서 전달받게 하려고 다음과 같이 파일을 만들었습니다.

-pipe1.php-

<?php
	echo "ddddd<br>";
	//system("./cpipe1");
	$ph=popen("cpipe1","r");
	while(1) {
		$gettingfrompipe=fgets($ph,1024);
		$totstr.=$gettingfrompipe;
	}
	echo $totstr."<br>";
	pclose($ph);
?>

-cpipe1.cc-

#include <iostream>
using namespace std;
#include <unistd.h>
#include <cstring>
int main() {
	wcout<<"Dump the garbage."<<endl;
	int pipes[2];
	pipe(pipes);
	close(pipes[0]);
	while(1) {
		write(pipes[1],(const char*)"draw",strlen("draw"));
	}
	return 0;
}

위와 같이 하면 draw라는 문자열을 파이프를 통해서 pipe1.php 파일이 전달받고 그 결과를

echo $totstr."
";

로 출력해야 하는데, 그 결과가 스크립트에서 출력되지 않습니다. pipe1.php와 cpipe1.cc의 무엇을 고쳐야 통신이 제대로 될까요?

shint의 이미지

http://php.net/manual/en/function.popen.php
여기 예제가 도움이 될지도 모르죠...

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com