In bash/"the terminal" there are things called file pointers. When you run any given command, there are at least THREE file pointers, called 1 2 3.
1 is standard output "STDOUT"
2 is error output "STDERR"
3 is standard input "STDIN"
When you run this:
$o=shell_exec('pdftotext -enc UTF-8 '.$path.' pdf.txt');
you are getting ONLY standard output. But what if there is no standard output?
Maybe you have an ERROR. And you really want to be looking at both STDOUT + STDERR.
You can redirect the pointer for STDERR to STDOUT by adding this to your bash/sh command:
$o=shell_exec('pdftotext -enc UTF-8 '.$path.' pdf.txt 2>&1');
Now when you run this:
$path = 'asd9ajs09dj039jadad'; //doesn't exist
echo shell_exec('pdftotext -enc UTF-8 '.$path.' pdf.txt 2>&1');
pdf2text: command not found
But, for you it will probably be something like
Could not open input file: asd9ajs09dj039jadad
Taken from my own code:
$cmdStr = CONFIG::PATH_TO_PYTHON2.' '.CONFIG::PATH_TO_PYTHON_PARSER.' '.$file->getDiskPath().' 2>&1'; //also send stderr to stdout
exec($cmdStr, $buffer); //send command to terminal, capture output in a buffer
You can also make your own custom file pointers or perhaps you are familiar with "piping" standard output into another programs standard input:
echo ASDF_ASDF_ASDF_ASDF | tr 'S' "D"
echo ASDF_ASDF_ASDF_ASDF | tr 'S' "D" | tr 'D' "F"
:p hope this helps some