|
From: <php...@li...> - 2009-09-07 10:01:59
|
> > hi, Aplogies if you receive the same mail more than once! > > > I tried calling php fucntion from java file but I am getting below > exception. > > caught exceptionjava.io.IOException: Cannot run program "php-cgi": > CreateProcess error=2, The system cannot find the file specified. > > I tried running the java file by having JavaBridge.jar and php-script.jar > files in classpath.Though in my javafile I am calling the remote php script > actually my requirement is to call php functions from standalone java file(I > tried doing the sam but got the same error).Can any body give step by step > way of creating a standalone java file and calling the php script from it.I > also need what are the jar files you place in classpath and other supporting > files require to execute them properly. > > Please find java file and php files below. > > I am need to do this asap.Any help is highly appreciated. > > > java file > > ===================================================================================== > import javax.script.*; > import java.net.*; > import java.io.*; > class SampleTest { > public static void test(Integer month) throws Exception { > try{ > ScriptEngine e = new > ScriptEngineManager().getEngineByName("php-invocable"); > ByteArrayOutputStream out; > OutputStreamWriter writer; > e.getContext().setWriter(writer=new OutputStreamWriter(out=new > ByteArrayOutputStream())); > Object res=e.eval(new php.java.script.URLReader(new URL(" > http://localhost:8080/JavaBridge/eg.php"))); > System.out.println("Got here"); > ((Invocable)e).invokeFunction("writeName", new Object()); > //System.err.println(((Invocable)e).invokeFunction("writeName", > new Object())); > ((Closeable)e).close(); > System.err.println("PHP exit() code:" + String.valueOf(res)); > System.err.println("PHP output:" + String.valueOf(out)); > }catch(Exception e){ > System.out.println("caught > exception"+e.getLocalizedMessage()); > } > } > public static void main(String s[]) throws Exception { > test(new Integer(12)); > } > } > > ========================================================================================================= > Php File: > > ========================================================================================================= > <?php require_once("java/Java.inc"); > function writeName() > { > echo "Kai Jim Refsnes"; > } > ?> > > ========================================================================================================== > > Thanks, > Pavan. > |