1

Im trying to execute a java Jar by PHP Exec() function.

 $encryptPass = exec('/usr/bin/java -Djava.awt.headless=true -jar /Users/sadasda/Desktop/EncryptTest.jar test123');

However all i get in output is blank string. I have given full paths to java and Jar. What could i be doing wrong?

1 Answer 1

1

There are a few things that could be going on. Some are:

  • The paths could be wrong. (Don't discount the possibility of a silly mistake ... )
  • There could be a bug in the Java app. (Have you tried running the command with the same args from the command line? Have you tried capturing the "standard error" stream from the java command in PHP?)
  • The java app could be expecting something on its "standard input" stream ... rather than in the command arguments.
  • The hardened OS could be blocking PHP from executing arbitrary external applications. (For example, SELinux in enforcing mode, or AppArmor.)
Sign up to request clarification or add additional context in comments.

2 Comments

im able to execute the jar from commandline successfully. My OS is MacOs. How to capture the standard error stream from the java command in PHP?
1) I don't know (not a PHP person). 2) This suggests that the problem is not bullet point #2, and probably not #1.

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.