0

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.

3
  • ya it works from the command prompt but not from a php page. Commented Aug 4, 2011 at 12:43
  • THe user your Apache (or whatever you use) server is using needs to have execute privileges for java. Commented Aug 4, 2011 at 13:09
  • @Sanjay, beware of any malicious code a user can inject in '$retval', incase the post parameter values are not sanitized. This would be a huge security concern on a public facing site. Commented Aug 4, 2011 at 14:14

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

actually the java program is used to update a database but its not getting updated. i tried giving the full path but the same thing is happening.
0

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? :)

1 Comment

The java program executes perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.