You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Dave Coventry <dg...@gmail.com> on 2010/01/03 06:49:17 UTC

Can't execute Java from PHP

I can't run my Java HSSF app from PHP.

I've asked on PHP forums but everybody seems as perplexed as I.

Perhaps someone on here has had similar problems and either knows the
answer or can suggest steps to take to debug it.

The following line in my PHP script fails. nothing prints out, it just
returns FALSE.
~~~~~~~~~ 8< ~~~~~~~~~~~~
system('java -jar /home/dave/web/drupal/java/dist/emp.jar');
~~~~~~~~~ 8< ~~~~~~~~~~~~

However, this works: (It prints out the help info normally associated
with incorrect parameters passed to Java.)
~~~~~~~~~ 8< ~~~~~~~~~~~~
system('java -jar');
~~~~~~~~~ 8< ~~~~~~~~~~~~



This also works:
~~~~~~~~~ 8< ~~~~~~~~~~~~
system("ls -l /home/dave/web/drupal/java/dist/emp.jar");
~~~~~~~~~ 8< ~~~~~~~~~~~~

It prints out a listing of /home/dave/web/drupal/java/dist/emp.jar
including permissions.

Thanks,

Dave C.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: Can't execute Java from PHP

Posted by Bobby Kent <bo...@gmail.com>.
Hey Dave,

IIRC the value 0 is equivalent to FALSE in PHP, and the return value of
system is the one provided by the OS.  If you run the java command from the
command line and immediately follow up with "echo $?" you'll see that the OS
reports a return value of 0 on success (unless you've explicitly set a
non-zero exit code in emp.jar).  I think this means that all is well between
PHP and Java.  To be sure add some System.out.println statements in your
java code to see if it's being executed ...

Cheers,

Bobby

-----Original Message-----
From: Dave Coventry [mailto:dgcoventry@gmail.com] 
Sent: Sunday, January 03, 2010 00:49
To: POI Users List
Subject: Can't execute Java from PHP

I can't run my Java HSSF app from PHP.

I've asked on PHP forums but everybody seems as perplexed as I.

Perhaps someone on here has had similar problems and either knows the
answer or can suggest steps to take to debug it.

The following line in my PHP script fails. nothing prints out, it just
returns FALSE.
~~~~~~~~~ 8< ~~~~~~~~~~~~
system('java -jar /home/dave/web/drupal/java/dist/emp.jar');
~~~~~~~~~ 8< ~~~~~~~~~~~~

However, this works: (It prints out the help info normally associated
with incorrect parameters passed to Java.)
~~~~~~~~~ 8< ~~~~~~~~~~~~
system('java -jar');
~~~~~~~~~ 8< ~~~~~~~~~~~~



This also works:
~~~~~~~~~ 8< ~~~~~~~~~~~~
system("ls -l /home/dave/web/drupal/java/dist/emp.jar");
~~~~~~~~~ 8< ~~~~~~~~~~~~

It prints out a listing of /home/dave/web/drupal/java/dist/emp.jar
including permissions.

Thanks,

Dave C.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Can't execute Java from PHP

Posted by Nick Burch <ni...@alfresco.com>.
On Sun, 3 Jan 2010, Dave Coventry wrote:
> The command  'java -jar /home/dave/web/drupal/java/dist/emp.jar' works
> fine on the command line.

Could it simply be a path issue? i.e. the "java" command is on your path 
when run from the command line, but not when run from php?

Try giving the absolute path to the java binary in your system command

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Can't execute Java from PHP

Posted by MSB <ma...@tiscali.co.uk>.
Hello Dave,

Like David, I am not an expert with PHP - in fact, I have never used it
before - but I wanted to ask whether you have been able to isolate the
problem to just the POI libraries? What happens if, for instance, you create
a very simple class that counts from one to one hundred and writes the
results to a file, then try to run that as you have the POI based code? It
would be worth using Netbeans to create a distribution just as you already
have done just to see if this is somehow creating problems as well IMO.
Aside form that, I cannot offer any help at all I am afreaid.

Yours

Mark B


Dave Coventry-4 wrote:
> 
> Dave,
> 
> I appreciate the input.
> 
> The command  'java -jar /home/dave/web/drupal/java/dist/emp.jar' works
> fine on the command line.
> 
> I am using the Java HSSF code to upload spreadsheets into a database via
> PHP.
> 
> Has anyone attempted anything similar?
> 
> Other external functions are called from the same script without error.
> 
> 2010/1/3 David Fisher <df...@jmlafferty.com>:
>> Check your java classpath. Is poi properly included? I think that this is
>> the true issue guessing from your example.
>>
>> Of course, I am NOT a php person, but I guess
>>
>> system("set");
>>
>> or
>>
>> system("setenv");
>>
>> Regards,
>> Dave
>>
>> On Jan 2, 2010, at 9:49 PM, Dave Coventry wrote:
>>
>>> I can't run my Java HSSF app from PHP.
>>>
>>> I've asked on PHP forums but everybody seems as perplexed as I.
>>>
>>> Perhaps someone on here has had similar problems and either knows the
>>> answer or can suggest steps to take to debug it.
>>>
>>> The following line in my PHP script fails. nothing prints out, it just
>>> returns FALSE.
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>> system('java -jar /home/dave/web/drupal/java/dist/emp.jar');
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>>
>>> However, this works: (It prints out the help info normally associated
>>> with incorrect parameters passed to Java.)
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>> system('java -jar');
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>>
>>>
>>>
>>> This also works:
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>> system("ls -l /home/dave/web/drupal/java/dist/emp.jar");
>>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>>
>>> It prints out a listing of /home/dave/web/drupal/java/dist/emp.jar
>>> including permissions.
>>>
>>> Thanks,
>>>
>>> Dave C.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Can%27t-execute-Java-from-PHP-tp26999305p26999905.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Can't execute Java from PHP

Posted by Dave Coventry <dg...@gmail.com>.
Dave,

I appreciate the input.

The command  'java -jar /home/dave/web/drupal/java/dist/emp.jar' works
fine on the command line.

I am using the Java HSSF code to upload spreadsheets into a database via PHP.

Has anyone attempted anything similar?

Other external functions are called from the same script without error.

2010/1/3 David Fisher <df...@jmlafferty.com>:
> Check your java classpath. Is poi properly included? I think that this is
> the true issue guessing from your example.
>
> Of course, I am NOT a php person, but I guess
>
> system("set");
>
> or
>
> system("setenv");
>
> Regards,
> Dave
>
> On Jan 2, 2010, at 9:49 PM, Dave Coventry wrote:
>
>> I can't run my Java HSSF app from PHP.
>>
>> I've asked on PHP forums but everybody seems as perplexed as I.
>>
>> Perhaps someone on here has had similar problems and either knows the
>> answer or can suggest steps to take to debug it.
>>
>> The following line in my PHP script fails. nothing prints out, it just
>> returns FALSE.
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>> system('java -jar /home/dave/web/drupal/java/dist/emp.jar');
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>
>> However, this works: (It prints out the help info normally associated
>> with incorrect parameters passed to Java.)
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>> system('java -jar');
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>
>>
>>
>> This also works:
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>> system("ls -l /home/dave/web/drupal/java/dist/emp.jar");
>> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>>
>> It prints out a listing of /home/dave/web/drupal/java/dist/emp.jar
>> including permissions.
>>
>> Thanks,
>>
>> Dave C.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Can't execute Java from PHP

Posted by David Fisher <df...@jmlafferty.com>.
Check your java classpath. Is poi properly included? I think that this  
is the true issue guessing from your example.

Of course, I am NOT a php person, but I guess

system("set");

or

system("setenv");

Regards,
Dave

On Jan 2, 2010, at 9:49 PM, Dave Coventry wrote:

> I can't run my Java HSSF app from PHP.
>
> I've asked on PHP forums but everybody seems as perplexed as I.
>
> Perhaps someone on here has had similar problems and either knows the
> answer or can suggest steps to take to debug it.
>
> The following line in my PHP script fails. nothing prints out, it just
> returns FALSE.
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
> system('java -jar /home/dave/web/drupal/java/dist/emp.jar');
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>
> However, this works: (It prints out the help info normally associated
> with incorrect parameters passed to Java.)
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
> system('java -jar');
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>
>
>
> This also works:
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
> system("ls -l /home/dave/web/drupal/java/dist/emp.jar");
> ~~~~~~~~~ 8< ~~~~~~~~~~~~
>
> It prints out a listing of /home/dave/web/drupal/java/dist/emp.jar
> including permissions.
>
> Thanks,
>
> Dave C.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org