2013-02-27 38 views
4

我在CentOS上使用CutyCapt。 它通過終端工作正常,但它不能通過php exec函數工作。 我在終端開始通過xvfb的命令:CutyCapt與php exec

Xvfb :99 -screen 0 1024x768x24 

而且我'嘗試做的PHP腳本的截圖:

exec("DISPLAY=:99 /path/to/cutycapt --url=<some url> --out=<path/to/output>"); 

它不顯示任何錯誤,但沒有輸出文件(輸出目錄有chmod 777) 有人可以幫我嗎?

感謝

UPD: 也許是更好的某種方式,讓被Apache的Xvfb的執行?

+0

請嘗試下面的代碼和發佈結果。 '$ output = array(); $ return_var = null; $ result = exec(「DISPLAY =:99/path/to/cutycapt --url = --out = 」,$ output,$ return_var); var_dump($ result); var_dump($ output); var_dump($ return_var);' – Babblo 2013-02-27 17:51:00

回答

2

我設法讓CutyCapt在最後使用php成功運行。 $ _parameters通過AJAX傳遞給php腳本。希望這有助於...

case 'Output_Chart': { 

    // We always create the .png. We use the ImageMagick convert (IMC) command to make .pdfs 
    if ($_Suffix == 'pdf') { 
     $IMC = ";convert -page 735x850 '$_PathOut/$_ChartName.png' '$_PathOut/$_ChartName.pdf'"; 
    } else { 
     $IMC = ''; 
    } 

    // Prepare the query string for the CutyCapt URL 
    $sQuery_Pattern = '?Path=%s&iDL=%d'; 
    $sQuery   = sprintf($sQuery_Pattern, $_Path, $_iDL); 

    // Prepare CutyCapt's command and parameters (NB: query string and out parameter are enclosed in aposts for the shell) 
    $sCC_Cmd   = '/var/www/LF/Includes/CutyCapt'; 
    $sCC_URL   = "http://localhost/LF/LFPrint.html'$sQuery'";  // Note: Inner apostrophes 
    $sCC_Out   = "'$_PathOut/$_ChartName.png'"; 
    $sCC_Pattern  = ' --url=%s --out=%s --delay=%d --min-width=%d'; 
    $sCC_Options  = sprintf($sCC_Pattern, $sCC_URL, $sCC_Out, $_Delay, $_MinWidth); 
    //$sCC_CmdLine   = $sCC_Cmd . $sCC_Options . " 2> CutyCapt.err.txt"; 
    $sCC_CmdLine   = $sCC_Cmd . $sCC_Options . " 2> /dev/null"; 

    // Prepare the final command line with xvfb-run, CutyCapt, and the URL?QueryString 
    $sCC_CmdLine = 'xvfb-run --auto-servernum --server-args="-screen 0, 800x1000x24" ' . $sCC_CmdLine . $IMC; 
    exec($sCC_CmdLine, $aOutput = array(), $ret); 
    // Wait for and then return the results. sCC_CmdLine and aOutput are just for debugging 
    echo json_encode(array("ret" => $ret, "cmd" => $sCC_CmdLine, "Output" => $aOutput)); 
    break; 
} 
+0

最差的答覆..給出了這麼多的錯誤... – 2014-04-05 13:24:45