Click to See Complete Forum and Search --> : Calling An Openoffice Macro With Php - pls help


hagen00
04-20-2005, 12:53 PM
Hi there,

i wrote an OpenOffice macro that i call from the following shell script when running Linux in console mode ie not with a GUI. If i call this shell from the terminal, the macro runs fine. I've installed an Xvfb server (note "-display :1.0") that has allowed me to do this.

Code for shell:

#!/bin/bash

/opt/OpenOffice.org1.1.4/program/soffice -display :1.0 -headless "macro:///IntellincLib.Conversions.convertjpg"


But now i try call the shell from the following simple php script:

exec("PATH TO SHELL/convert_jpg");

I then enter ps -A to see what processes are running the following is displayed


? 00:00:00 convert_jpg
? 00:00:00 soffice.bin
? 00:00:00 soffice.bin <defunct>

So soffice obviously failed to do what it was supposed to do because it's <defunct> ie called the exit function. The shell convert_jpg however does seem to have been called since it is listed.

Why would soffice exit prematurely? I've had a look at various permissions of the folders, soffice, the macro and all should be ok.

I would really appreciate any help.

Thanks!

hagen

dalecosp
04-20-2005, 02:51 PM
<?php
$foo=system("/opt/OpenOffice.org1.1.4/program/soffice -display :1.0 -headless \"macro:///IntellincLib.Conversions.convertjpg\"");
?> ??

Thinks to think (off the top of my head):

Does php have permission to do what I'm asking?
Does the php function I'm calling do things differently from my shell scripts? If so, how?
If I'm using PHP under Apache (e.g. via the web), does the web user have a shell?
What's in the logfiles?
What about $DISPLAY?

hagen00
04-21-2005, 08:11 AM
Thanks for your reply!

I tried the system() function and the result was the same if i do a ps -A, except that my shell isn't called (obviously :)


? 00:00:00 soffice.bin
? 00:00:00 soffice.bin <defunct>


And this is why it is so weird:

Callling the shell from php seemed to work fine, since it was executing it, with the shell in turn launching OpenOffice, only for OpenOffice to close again.

Using the system function as you suggested went straight to OpenOffice, launched it, and then closed it down again (see ps -A display above)

But if i put the code below straight into the terminal, it works!


/opt/OpenOffice.org1.1.4/program/soffice -display :1.0 -headless "macro:///IntellincLib.Conversions.convertjpg"


The problem i think lies with OpenOffice although i really don't have a clue...I have made my macro available to all users (i think) and have given soffice read and execute permissions for all users.

Is it a permission problem somewhere?

Stumped...

hagen

hagen00
04-21-2005, 01:11 PM
Right, a Linux guru called Ed sorted me out! I'll admit i'm a beginner, this is day 3 on linux only.

The problem was the following.

- Apache was running as user nobody and hence had no rights, so he created a user httpd and installed OpenOffice for that user

- We then had to set Apache's home directory in my bash script --> export HOME=/home/httpd

- Then the problem was that the folder wasn't writeable for httpd to which my jpgs were exported to

Sounds simple, but for a beginner like me to find this problem, impossible.

Thanks ed

desastreux
12-05-2005, 06:48 PM
:) Hello everybody !

What a surprise to see i was not the only one to think about making that.
Since there are more and more web sites proposing to convert documents online, onto XML displaying, for exemple, it was a little strange to see that there were no stand-alone solutions, but it is.

Well, as i improved that it was impossible for me alone to find how to grab alone the Java filters classes in OpenOffice, and because I did not like solutions like ServOO or Xpub that makes you use OO socket and others heavy stuffs, I decided to use OO Macros, launched by command line.

Then, I guess, the same thing that happened to hagen00 finally happened to me.
Except that I am using Ms Windows and not Unix. :queasy:

There is perhaps also something of different in our two cases :
I am using Java classes Writer2LateX to convert SXW to XHTML : These classes are launched by the comand exec() of PHP and are running fine without any Apache more configs...

In the same time, if I use a bash file, or a windows .lnk, or even a class Java with Process.getRuntime.exec() inside, to launch OpenOffice it is well working since I don't ask this from PHP... :confused:

I have tried to configure my Apache server : I successed in creating users with passwords, and i am now with ".htaccess" and ".htpasswd" files in my project-directory...

But I find nothing about letting use OpenOffice by PHP, or admin kinds of rights...
If you, hagen00, could help me, and then perhaps others too, in explaining more details about how you manage to do with Ed ( even if it is on Linux server ) I would greatly appreciate ! :D

Of course, if everybody else has an other idea, I keep my eyes on the place...

Thank you guys to have spent your time in reding my request in a bad-english formulated ( am a french dude ! ) and kinds of regards !

THX

hagen00
12-06-2005, 03:34 AM
Hi desastreux

If i understand correctly, you want to launch an OO macro from PHP and your macro works fine if you launch it from Java or a windows link etc.

With PHP, try launching a windows batch file that calls OO.

<?php
exec("C:\path\to\my\batch\file.bat");
?>

And now the code for the batch file (file.bat):
@ECHO OFF

"c:\program files\OpenOffice.org2.0\program\soffice.bin" -invisible "macro:///YourLibrary.Conversion.YourMacro(%1)"

This should work fine. By the way, if you want to have the conversion taking place in the background, use the following piece of code instead of exec in PHP

Proc_Close (Proc_Open ("C:\path\to\my\batch\file.bat &", Array (), $foo)); where $foo has no value.

desastreux
12-06-2005, 04:41 PM
Hello Hagen00 !

THX to this very prompt answer !

I have yet tried all that I could to launch OpenOffice with the exec() PHP command.
( exec( Batch file, link, java, etc...) ) ...But in vain with the PHP5 inclued in WAMP while it is ok with PHP4.3 on easyPHP

As I explained it here too :
http://www.phpbuilder.com/board/showthread.php?p=10681598#post10681598

Then your tip is NOT working fine.

But I hava never tried :
Proc_Close (Proc_Open ("C:\path\to\my\batch\file.bat &", Array (), $foo));
I go back in a few minutes to say what happened.

desastreux
12-06-2005, 04:47 PM
Well, with this command, Firefox or I.E. go on with the PHP code but OpenOffice doesn't start more... Haven't you said that some configurations of Apache had surrounded your problem ?

desastreux
12-06-2005, 07:18 PM
Hi again !

( THIS POST IS ALSO ON THE OTHER TOPIC RELATED OF THE SUBJECT : Thanx to understand that it can makes sens here to have the same posts as the two subjects are very closed )

> After some tests , I saw that the problem seems to come from my Apache Configuration.

In fact, when i ask PHP to launch OpenOffice with the command exec(), it is doing it.
Whatever I am using PHP4 or PHP5 ( With the Wamp Server you cand find here :
http://www.wampserver.com ) , the results are the sames.

Process "sOffice.bin" and "sOffice.exe" are launched and my WebPage keeps as blocked as these processes ( It is for running a convert-macro of openOffice wich runs fine when OO is launched in local )

In the same time, if I try to kill Apache, it becomes only possible if I have killed "sOffice.exe" and "sOffice.bin" before...

Well, I have to try again with easyPHP and to see if the difference is really coming from WAMP' Apache. I would prefer to solve this, because WAMP uses PHP5 and I need it to perform a good job with XML without have to use a lot of externals modules...

Let me know if someone has an idea, please and Have all a good night !

hagen00
12-07-2005, 02:27 AM
...But in vain with the PHP5 inclued in WAMP while it is ok with PHP4.3 on easyPHP

That is very strange. I've successfully used WAMP with PHP5 to do exactly what you want to do on a windows environment. Sorry that i can't be of more help, but this really is a very strange problem. If i think of something i will post.

If you manage to find the problem, please post the solution here for the rest of us.

nobd7979
12-27-2005, 02:22 PM
sorry, no advertising on these boards...