Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently installed pdftk using instruction provided at stack overflow

I installed it, and run the commanded whereis pdftk the result was

/usr/local/bin/pdftk    /usr/bin/pdftk 

I have the powerpannel access and I saw it through it that pdftk actually exists at the location

i run the command pdftk --version, it was okay

but when in php i use

$command = "pdftk --help";
system("PATH=/usr/local/bin/ && $command",$response);
if ($response===FALSE){
   echo 'sorry error occured';
    echo $response;


the output is 127 the version i am using is 1.41 and the output '127' is something that i cant understand

can somebody guide me?


Actually, i was trying to generate dynamic pdf by filling a pdf form, my passthru was

 passthru("/usr/local/bin/pdftk hud3.pdf fill_form result.pdf output - flatten");

this was returning nothing

although header before the statement pops up for download, and I press save button to save it on local, it was not saving it on my hard drive. trying to debug the situation, and getting help from already asked question on sktack overflow, i thought to run pdftk first. that's where the above 127 situation rised, need guideline

share|improve this question
If you want to set an environment variable and then call an exec you can't use the && (I think the command right to the && gets called in a subshell and this won't have the env.-var). Just use system("PATH=/usr/local/bin/ $command",$response); or call it the way cjc did suggest (system("PATH=/usr/local/bin/$command",$response);). – boretom Mar 24 '12 at 12:59
thanks, see my update question please – Zaffar Saffee Mar 24 '12 at 13:37
Since I don't know pdftk: Does the command work if you execute it on the command line? Where are the hud3.pdf and result.pdf located? In the same directory as the PHP file? – boretom Mar 24 '12 at 14:05
yes..all these files are located at the same path..also..trying passthru('/usr/local/bin/pdftk --help') or any other command is not working – Zaffar Saffee Mar 24 '12 at 21:54
up vote 1 down vote accepted

A couple things.

1) Don't compile your own pdftk and stick it in /usr/local/bin/. You should use packages instead. The pdftk package is available in the RPMForge repo:

$ yum info pdftk
Loaded plugins: priorities, ps
Available Packages
Name        : pdftk
Arch        : i686
Version     : 1.44
Release     : 2.el6.rf
Size        : 906 k
Repo        : rpmforge
Summary     : PDF Tool Kit
URL         :
License     : GPL
Description : If PDF is electronic paper, then pdftk is an electronic staple-remover,
            : hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple
            : tool for doing everyday things with PDF documents. Keep one in the top drawer
            : of your desktop and use it to:

In fact, if your "whereis" is returning what you're showing, pdftk is already installed. Run rpm -qa |grep pdftk. If you don't get anything, install it via yum (look at to see how to add RPMForge to the available repos). In any case, remove the one you compiled.

2) Your system statement in PHP is: "PATH=/usr/local/bin/ && pdftk --help". This will set the PATH to only /usr/local/bin and then execute pdftk --help if it finds it in the PATH. The return code 127 is from bash, and indicates that it could not find pdftk (which is weird, because you're specifying the one and only PATH, but that's a different matter) or maybe the "&&" confused the PHP system function. Anyway, why not just use: system("/usr/local/bin/pdftk --help", $response)?

share|improve this answer
system("/usr/local/bin/pdftk --help", $response)? return still the same 127,,,what should I do now? – Zaffar Saffee Mar 24 '12 at 22:24
Does passthru('/usr/local/bin/pdftk') return anything? Running it from the command line returns the command synopsis. – cjc Mar 24 '12 at 22:55
it returns nothin in php,,in command..when I go to bin, and run dir shows that pdftk is there – Zaffar Saffee Mar 24 '12 at 23:39
I was going to suggest posting to Stackoverflow, since this seems to be a PHP issue rather than a systems issue, but you've already done so. – cjc Mar 25 '12 at 0:01
please see comments below the question – Zaffar Saffee Mar 25 '12 at 0:06

The function system returns the status code of the executed command not the actual string output. You can check this page. So, the value 127 is the exit status of the executed command.

To get the text output, you need to use shell_exec.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.