简体   繁体   中英

Running exec command php

I have just installed pdf2htmlEX without any issues. If I run the command on the server it works fine. So I know the library itself is doing what it is supposed to do. If I run the command in php via the exec function nothing happens. I assume exec is used in this instance??

In PHP

// doesn't work
$output = exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf');
// doesn't work
$output = shell_exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf');

If I run a general command in the exec function it works fine, so I know exec is enabled and working as expected.

// works fine
$exec =  exec('pwd', $output);
print_r($output);

Direct on Command Line not in PHP

// works and generates the file as expected.
pdf2htmlEX --zoom 1.3 pdf/test.pdf

Any help would be greatly appreciated.

Command line reference for library https://github.com/coolwanglu/pdf2htmlEX/wiki/Quick-Start

EDIT: After some further digging, it could be that the php script runs as a different user to the command line. My question would then be how do I check/fix this?

You just have to add the output html path and file name in your command :

Most of pdf_to_something packages usage with exec() is package_name [options] <input-filename> <output-filename>

$path = 'path/to/your/folder/';

$command = 'pdf2htmlEX '.$path.'test.pdf '.$path.'test.html';

exec($command);

请尝试以下操作,并检查您的文件是否在工作目录中创建。

exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf',$output);

pdf2htmlEX doesn't output anything.

$cmd=  "pdf2htmlEX --zoom 1.3 test/test.pdf";
exec($cmd, $output);

Will create a test.html file in the current directory.

Are you expecting something else?

Note: i've tested this on ubuntu by installing pdf2htmlEX with

sudo apt-get install pdf2htmlex

To get the output,

$a = file_get_contents("test.html"); 
echo $a;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM