0

I have a php file, javaCompile.php that looks like this:

<?php
    echo "Hello World!<br/>";
    exec("javac C:/xampp/htdocs/src/Test.java");
    echo "Finished!";
?>

If I run it from a windows command line, the java file is compiled and the Test.class file is created.

When I try to run it through localhost, I do get the 2 echo statements, but the class file does not get created.

Any help with this would be appreciated. Javac is located in the standard install location, and the location is set in the path, but I am thinking the php server does not utilize the windows path.

Grant Foster
  • 722
  • 2
  • 11
  • 21
Joth
  • 155
  • 1
  • 2
  • 10

1 Answers1

0

Try using shell_exec for full output.

<?php
   $out = shell_exec('cd C:/xampp/htdocs/src');
   var_dump($out);
   $out = shell_exec('dir');
   var_dump($out);
   $out = shell_exec('javac Test.java');
   var_dump($out);
?>

Please check this link

Shuhail Alam
  • 174
  • 1
  • 8
  • Thanks Shuhail - I'm getting a NULL value output on the change directory, but the dir command still gives the file listing of the original location htdocs. The compile is returning a file not found error – Joth May 13 '18 at 05:01
  • Directory changing output will be null. Please check your directory. it should work. – Shuhail Alam May 16 '18 at 07:16