Guest
Public paste!

Christian Sciberras

By: a guest | Mar 19th, 2010 | Syntax: PHP | Size: 0.60 KB | Hits: 219 | Expires: Never
Copy text to clipboard
  1. function pipeExec($cmd,$input=''){
  2.         $proc=proc_open($cmd,array(0=>array('pipe','r'),1=>array('pipe','w'),2=>array('pipe','w')),$pipes);
  3.         fwrite($pipes[0],$input);
  4.         fclose($pipes[0]);
  5.         $stdout=stream_get_contents($pipes[1]);
  6.         fclose($pipes[1]);
  7.         $stderr=stream_get_contents($pipes[2]);
  8.         fclose($pipes[2]);
  9.         $rtn=proc_close($proc);
  10.         return array(
  11.                 'stdout'=>$stdout,
  12.                 'stderr'=>$stderr,
  13.                 'return'=>$rtn
  14.         );
  15. }
  16.  
  17. $cmd=KCS_APPLICATIONS::main()->path().'libraries/wkhtmltopdf/wkhtmltopdf-amd64'; // path to the static executable
  18. $web='http://google.com/';
  19. $pdf=self::pipeExec('"'.$cmd.'" "'.$web.'" -');