I am writing a small php script that compiles java code using the exec function. I want the compile to fail and write compile issues to a log file but the log file doesn't contain anything when I cat it. How can I get compile error messages into that log file?
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// When it doesn't compile, it doesn't write error to log.txt
$class = 'class runrunrun
{
public static void main (String args[])
{
System.out.println("Hello world!");
FAIL NOW!!
}
}';
$myfile = fopen("runrunrun.java", "w+") or die("Unable to open file!");
fwrite($myfile, $class);
fclose($myfile);
exec("javac runrunrun.java >> log.txt", $foo, $compileFlag);
if ($compileFlag != 0) {
echo "COMPILE ERROR\n";
}
?>
Thanks in advance
EDIT: I'm trying to run this on an AFS Server. Here's the output from lsb_release. I hope this clears it up a bit
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: Scientific
Description: Scientific Linux release 6.8 (Carbon)
Release: 6.8
Codename: Carbon
The default shell is BASH