2014-04-30 1 views
0

스크립트에서 PHP exec()를 사용하여 PDF 파일을 PDFTK와 병합합니다.PHP exec를 사용할 때 PDFTK에서 전체 오류가 발생합니다.

PHP 문서에서 : exec function 두 번째 인수가 제공되면 콘솔 출력의 각 줄을 나열합니다. 내가 얻는 것은 모두 빈 배열이다. 코드의

예는 사용 :

exec(pdftk "file1.pdf" "file2.pdf" Merged_File.pdf, $output = array(), $result); 

내가 콘솔에서 코드를 실행하면 나는 성공적으로 오류를 얻을 수 있지만, 내 응용 프로그램이 전체 텍스트 오류에 액세스 할 수 있도록 내가 좋아하는 것입니다.

답변

2

stderr의 메시지를 proc_open을 사용하여 얻으려고합니다. 다음과 같이 입력하십시오 :

<?php 

$cmd = "/path/to/script arguments here"; 
$cwd = dirname(__FILE__); 
$descriptorspec = array(
    0 => array("pipe", "r"), // stdin 
    1 => array("pipe", "w"), // stdout 
    2 => array("pipe", "w"), // stderr 
); 

if (($process = proc_open($cmd, $descriptorspec, $pipes, $cwd, null)) !== false) 
{ 
    // Standard output 
    $stdout = stream_get_contents($pipes[1]); 
    fclose($pipes[1]); 

    // Errors 
    $stderr = stream_get_contents($pipes[2]); 
    fclose($pipes[2]); 

    proc_close($process); 
} 

?> 
+0

감사합니다. 잘 작동합니다. –

관련 문제