capturing java compile errors with php
Posted: Sun Feb 15, 2009 6:12 pm
i am trying to write a php script similar to that found at http://www.javabat.com
and im having some problems hope you can help.
This is some sample java code from a text box:
And this is the php that i use to write the file.
if there are no compilation errors the file gets written to my web server as expected but i cannot capture any errors if they exist 
and im having some problems hope you can help.
This is some sample java code from a text box:
Code: Select all
public static int timesTwo(int x){
//should throw a return type error
return;
}
Code: Select all
//SRC from post
$userCode = $_POST['src'];
//TODO: GET FROM SESSION
$user="admin";
$questionId=1;
//Unique file name guarentees file overwriting
//java classes have to start with a letter
$fileName = "x".sha1($user.$questionId);
$fp = fopen($path.$fileName.".java","w");
//default class
$src = "
//Genereted by runTest.php
public class $fileName{
public static void main(String args[]){
System.out.println(timesTwo(1));
}
$userCode
}";
fwrite($fp,$src);
fclose($fp);
/*
Compiles and runs the code then echos the output
for user feedback
TODO:
Infinite Loop Checks
Compilation Error Checks
Sanatize inputs!!!!!
*/
echo "Compiling... \n";
//command for compiling a text file
echo system("javac ".$path.$fileName."java",$compileOutput);.