Sanjay Huilgol
Sanjay Huilgol

Reputation: 1

how should i run a java program from a php page,on submitting a form?

i ve a .php page and now i want to run a java program in the backend after submitting a form in php.i ve tried using exec(), system() functions and sadly its not working. please help me out. This is the code snippet:

if($_POST["ADD"])
{
        echo "Phrase has been added now"."<br />";
        $lastline=exec("java -Dwordnet.database.dir=D:\wordnet\2.1\dict Process",$retval); 
}

Process is my main class which I want to be executed.

Upvotes: 0

Views: 135

Answers (2)

cweiske
cweiske

Reputation: 31088

First, you posting an error message would have been helpful. Checking the return code is also wise.

Second, specify the full path to java, e.g. /usr/bin/java instead of just using java.

Upvotes: 1

Svilen
Svilen

Reputation: 1437

Start the java process in debug mode i.e. with jdwp enabled. Then connect to the java process with some debugger for example jdb but better use full fledged IDE like Eclipse. Make sure you set suspend flag to y otherwise the java process will terminate before you are able to establish debug session to it

exec("java -Xrunjdwp:transport=dt_socket,address=9002,server=y,suspend=y <the rest of command>")

A somewhat simple solution is to use logging in you java app, configured to write to some file, so that you can check whats going wrong during execution.

Btw, are you sure that the java program is actually getting executed? :)

Upvotes: 0

Related Questions