9

I'm trying to run a .jar application from PHP using exec:

exec('java -jar parser.jar $inputstring 2>&1', $output);

I can get it to run on cmd, and java -version returns so I have java installed. It seems like this is a path issue, but I am at my wits end.

I've tried specifying the full path, adding C:\Program Files (x86)\Java\jdk1.8.0_91\bin; to System Variables, using shell_exec, no avail. I get the same error.

Any help would be greatly appreciated.

7
  • 3
    Show how you added the full path. there's spaces in there. if you didn't quote the path, e.g. shell_exec('"C:\Program files\...."), then you'll be attempting to run a program named c:\program.exe, with argument files\.... Commented Jul 8, 2016 at 15:06
  • I have: shell_exec('"C:\Program Files (x86)\Java\jdk1.8.0_91\bin\java.exe" -jar parser.jar $inputstring 2>&1'); If I don't have 2>&1 it's blank. With it I get the same 'java' not recognized error. Commented Jul 8, 2016 at 15:16
  • 2>&1 redirects stderr to stdout, which is why you get the error message. shell_exec only returns stdout, so you'd never see the error message. Commented Jul 8, 2016 at 15:19
  • You need to escape your backslashes. shell_exec ('"C:\\Program Files\\... Commented Jul 12, 2016 at 20:52
  • Try to echo the $PATH environement variable and see whether java is really in your path. Does the PHP script run under the same user as your cmd line test? Commented Jul 19, 2016 at 7:40

1 Answer 1

1

Use this....

exec('java -jar parser.jar '.$inputstring.'2>&1', $output);
or
shell_exec("java -jar parser.jar $inputstring 2>&1 $output");
or
string exec ( 'java -jar parser.jar'  [, array &$output [, int &$return_var ]] )
Sign up to request clarification or add additional context in comments.

Comments

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.