2

I have a working web php app. I'm working on win 7 and using apache.

Now I'm trying to execute this java command in php and display result on site:

exec("java -jar C:\webroot\ipt\themes\ipt\views\site\Skills.jar 5 10 5.5 10 2 5 8 3 10 6 11 2 15 4", $output);

    for ($index = 0; $index < count($output); $index++) {
        echo $output[$index]." ";
    }

However $output is an empty array - no output. I'm not getting any error or crash. Output is only a basic string. I tried to enter this same command in cmd and it work as it should - returning expected output.

So I tried different command to see if it's not problem with exec(), so I tried 'ipconfig' which displayed output on site flawlesly.

Because of this I think it has something to do with either PHP or Apache (or both).

I searched for some similar problems of other people and tried:

  • entering full path of java to the command: C:\Program Files (x86)\Java\jre1.8.0_20\bin\java - jar ... - didn't work
  • to change permisions to the .jar file to full access (including parent directories) - didn't work.

So I want to ask if someone doesn't know solution to this problem.

Thanks

2

1 Answer 1

1

Make sure that you are able to run this command without any problems in your console directly.

Change your exec to the following:

exec("java -jar C:\\webroot\\ipt\\themes\\ipt\\views\\site\\Skills.jar 5 10 5.5 10 2 5 8 3 10 6 11 2 15 4 2>&1", $output);

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

2 Comments

Thank you. That worked, but just a small question: what does this '2>&1' part mean?
It ensures that the output goes to the PHP handler that is handling the shell execution.

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.