1

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
it looks like i can only run one exec() per script.
Have you try system instead: id2.php.net/manual/en/function.system.php ?
yes i tried system as well. subsequent calls to pdftk were an issue.
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.