tags:

views:

146

answers:

2

I have two subsequent exec commands. The first executes without issue the second however is throwing an error:

exec('/usr/bin/pdftk A='. trim($original) .' cat A1 output '. trim($onepage), $output, $error);
var_dump($output); var_dump($error);

exec('/usr/bin/pdftk '. trim($onepage) .' background watermark.pdf output '. trim($modified), $output, $error);
var_dump($output); var_dump($error); 

The first produces:

array(0) { } int(0) 

The second:

array(0) { } int(1) 

The permissions on the php script and directories are exactly the same. I've tried ecaping the exec command using escapeshellargs with no luck either.

+1  A: 

I'm not sure what your error is, but I would recommend that you reduce some of the background noise so that you can see the problem easier. What I mean by this is the following...

Take

exec('/usr/bin/pdftk A='. trim($original) .' cat A1 output '. trim($onepage), $output, $error);
var_dump($output); var_dump($error);

exec('/usr/bin/pdftk '. trim($onepage) .' background watermark.pdf output '. trim($modified), $output, $error);
var_dump($output); var_dump($error); 

And do

$command1 = '/usr/bin/pdftk A='. trim($original) .' cat A1 output '. trim($onepage);
$command2 = '/usr/bin/pdftk '. trim($onepage) .' background watermark.pdf output '. trim($modified);

exec($command1, $output, $error);
var_dump($output); var_dump($error);
echo $command1;

exec($command2, $output, $error);
var_dump($output); var_dump($error); 
echo $command2;

That way you can cut and paste the output of the command issued onto the unix command line, and perhaps get a better view of what is going on at the unix level.

Bill
The error is that the second command is not processed at all and the var_dump() of the error returns 1 which means there was an error.
lackingpregmatch
it looks like i can only run one exec() per script.
lackingpregmatch
Have you try `system` instead: http://id2.php.net/manual/en/function.system.php ?
Donny Kurnia
yes i tried system as well. subsequent calls to pdftk were an issue.
lackingpregmatch
A: 

What ended up working was the following:

   $descriptorspec = array(
      0 => array("pipe", "r"), 
      1 => array("pipe", "w"));
   proc_open('/usr/bin/pdftk '. trim($onepage) .' background watermark.pdf output '. trim($modified), $descriptorspec, $pipes);
lackingpregmatch