简体   繁体   English

运行exec命令php

[英]Running exec command php

I have just installed pdf2htmlEX without any issues. 我刚刚安装了pdf2htmlEX,没有任何问题。 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. 如果我通过exec函数在php运行命令,则不会发生任何事情。 I assume exec is used in this instance?? 我假设在这种情况下使用exec

In PHP 在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. 如果我在exec函数中运行常规命令,则可以正常运行,因此我知道exec已启用并按预期工作。

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

Direct on Command Line not in PHP 直接在命令行中不在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 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. 编辑:经过进一步的挖掘后,可能是php脚本以与命令行不同的用户身份运行。 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 : 您只需要在命令中添加输出html路径和文件名:

Most of pdf_to_something packages usage with exec() is package_name [options] <input-filename> <output-filename> exec()的大多数pdf_to_something软件包用法是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. pdf2htmlEX不输出任何内容。

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

Will create a test.html file in the current directory. 将在当前目录中创建一个test.html文件。

Are you expecting something else? 您还期待其他吗?

Note: i've tested this on ubuntu by installing pdf2htmlEX with 注意:我已经在ubuntu上通过安装pdf2htmlEX

sudo apt-get install pdf2htmlex

To get the output, 要获得输出,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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