× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'm exploring ways to give PHP scripts running on a
non-Series server access to iSeries files and
programs. 

This message shows how to call Java programs from PHP
scripts. Calling Java prograns from PHP scripts is the
first step toward using Toolbox for Java to give PHP
scripts access to DB2 files, CL commands, CL programs,
RPG programs, and Cobol programs on the iSeries. 

My test environment is PHP running as an Apache 1.3
module on a W2K machine with a network connection to
an iSeries server.  I have installed j2sdk1.4.1_01 on
my W2K machine. I have created a directory called
'C:\javalinks' to hold my Java programs and the
Toolbox for Java package (jt400.jar). 

My system CLASSPATH includes the 'C:\javalinks'
directory. If the system CLASSPATH does not include
the directory containing the Java programs, then you
must store each Java program in the same directory as
the PHP script that executes it. This gets to be a
little annoying when the PHP script that executes the
Java program is included in another PHP script using
the 'include' or 'require' statement. The Java program
must be in the same directory as the PHP script
containing the 'include' or 'require' statement.

Here is the code for a very simple Java program:

public class JavaLink1 {
 public static void main (String args[ ]) {
  String greeting = "Hello from Java!";
  System.out.println(greeting);
 }
}

Compile the program. Place the JavaLink1.class file
in a directory included in the CLASSPATH or in the
same directory as the PHP sript that will execute it.

Below is a PHP script that executes the Java program.
It actually contains code for executing the Java
program with 3 different Program Execution Functions,
though the code for the 'exec' function and the
'system' function have been commented out. You could
also try the 'passthru' function or the backtick
operator.  

<?php
 //The 'exec' command executes the Java 
 //program with no output. Nothing will
 //appear in a Web page. 
   //exec('java JavaLink1'); 
 
 //The 'system' command executes the Java
 //program and returns the last line of 
 //output. This output appears in the Web 
 //page even if not displayed using an echo
 //or print statement.
   //system('java JavaLink1');
 
 //The 'shell_exec' executes the command 
 //and requires output to be put in a 
 //variable for display using 'echo' or 
 //'print'. This lets you check the output
 //and respond accordingly. 
   $java = shell_exec('java JavaLink1');
   echo($java);
?>

If you include this PHP script in a Web page, then the
words 'Hello from Java!' should appear in your Web
page.

The next step is to write Java programs that access
iSeries resources using Toolbox for Java. I'll play
around with that for a few days and share what I find.

Later,
Kelly


                
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.