I have to convert some PDF files to TXT. I end up with "less" command, because for example pdftotext has some problems with tables in PDF. The problem is that when I ran the command from exec function (or shell\_exec/system), less just showing me information, that selected PDF is binary file and result file is just TXT with PDF data in it. But when I do the same thing normally in terminal, everything is ok. I also tried to login as www\_data user and ran command as this user, but there is also no problem. 

Command: 

```
$ less /var/www/original.pdf > /var/www/new.txt

```

PHP code:

```
exec("less -f /var/www/original.pdf > /var/www/new.txt 2>&1");

```

Result from PHP exec:

```
"/var/www/original.pdf" may be a binary file.  See it anyway?

```

The "-f" option in exec command is there because then you don't need to press "y" for "yes, I want to see it anyway."

`set | grep less` yields:

```
LESSCLOSE='/usr/bin/lesspipe %s %s'
LESSOPEN='| /usr/bin/lesspipe %s'
            Lossless LZW RLE Zip' -- "$cur" ));
                _apport_parameterless
                _apport_parameterless
                _apport_parameterless
                _apport_parameterless
_apport_parameterless () 

```