0

I have a PHP Project with the name itext. Inside this folder I have a workspace folder. So the Path to the Java Class file is like this:

itext/workspace/sampleproject/checkFonts.java

I have an index.php file in itext folder. How can I execute the shell_exec command in the index.php for the java file located in the above path?

UPDATE:

As per the answer I tried out stuffs and executed the below code and it works but I am getting the below error:

$output = array();
exec('java workspace/itext/src/itext/CheckFonts 2>&1',$output);
print_r($output);

Error:

Array ( [0] => Error: Could not find or load main class workspace.itext.src.itext.CheckFonts )

Abhinav
  • 8,028
  • 12
  • 48
  • 89
  • This may be helpful http://stackoverflow.com/a/3023715/1793718 – Lucky Aug 18 '15 at 07:43
  • Your error is related to the original question as is more a matter of your coding error. You should open a new question if you have a problem with your code. – Trung Nguyen Aug 19 '15 at 14:30

1 Answers1

1

You can specify any path relative to the file your code is running from. So from your index.php the path would be workspace/sampleproject

If you want to use the full explicit directory you can use realpath() function:

realpath('workspace/sampleproject');

Here's a guide to running Java at the command line for windows environment: http://www.skylit.com/javamethods/faqs/javaindos.html

Your example code might be:

$javaPath = realpath('workspace/sampleproject');
$output = shell_exec('C:\ProgramData\Oracle\Java\javapath\java.exe '
                     . $javaPath . DIRECTORY_SEPARATOR . 'checkFonts');`
Trung Nguyen
  • 519
  • 3
  • 18