PHP exec error without errors

I would like to automate the export of the .odf file to .pdf .

I tried something called unoconv .

When you enter the Windows command prompt, everything is correct.

 >"C:\Program Files (x86)\OpenOffice 4\program\python.exe" "C:\Program Files (x86)\OpenOffice 4\program\unoconv-master\unoconv" -f pdf path/to/myfile.odt 

After using in a PHP script nothing works. The error does not appear.

 exec('"C:\Program Files (x86)\OpenOffice 4\program\python.exe" "C:\Program Files (x86)\OpenOffice 4\program\unoconv-master\unoconv" -f pdf path/to/myfile.odt'); //or shell_exec('"C:\Program Files (x86)\OpenOffice 4\program\python.exe" "C:\Program Files (x86)\OpenOffice 4\program\unoconv-master\unoconv" -f pdf path/to/myfile.odt') 

I also tried to avoid \ or use ' and " in a different way, but none of my tests were final.

 $test = exec($cmd, $output, $return); echo var_dump($test); echo var_dump($output); echo var_dump($return); 

Let me

 //echo var_dump($test)give nothing //echo var_dump($ouput); array (size=0) empty //echo var_dump($return); int 1 

This sounds like a permissions issue, but I also checked this and all folders are accessible for PHP.

+5
source share
2 answers

I would add this as a comment instead, but not enough rep ...

I had this problem when switching from a WAMP server to IIS, and as you said, this is a permission issue. It turns out that I had to give the user "IUSR" and the group "IIS_IUSRS" full permissions to execute it.

Later, I came across something similar, and I believe that I decided to just change the work of the IIS user with the administrator, but this is probably not recommended.

Of course, it will not matter if you are not using IIS, but I will leave it here just in case.

0
source

Checking the exotic code, python.exe has been overwritten and is not applicable. The code in the original message was almost correct. My bad.

For curious people, this is my last code with an easy to use feature.

createPDF.bat

 @echo off set arg1=%1 set arg2=%2 cd "C:\Program Files (x86)\OpenOffice 4\program\" python.exe "C:\Program Files (x86)\OpenOffice 4\program\unoconv-master\unoconv" -f pdf -o %arg2% %arg1% 

createPDF.php

 function createPDF($from, $to) { //Launch the .bat, do not forget the double backslash $handle = popen("start /B path\\to\\createPDF.bat ".$from." ".$to, "r"); //Debug if needed //echo "'$handle'; " . gettype($handle) . "\n"; //$read = fread($handle, 2096); //echo $read; //Close the socket pclose($handle); } 

And now, when I need to convert the odt file to pdf, I just need to do the following

test.php

 include_once($_SERVER['DOCUMENT_ROOT']."path\to\createPDF.php"); //createPDF(source, destination), do not forget the double backslash (\\) createPDF("E:\\A\\strange\\path\\to\\Report.odt" , "D:\\Final_report"); 
0
source

Source: https://habr.com/ru/post/1238113/


All Articles