Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
//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);.
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
Not sure how to make compile errors print to stdout but you can direct them to a file and then check if the file has anything in it.
If the file has any contents then there were errors and you can show them to the user.
HI again
That was my first thought and it didnt work for me on windows.
Did you have to change any javac settings or anything?
Or are you using linux perhaps? I'm just wondering in case I ever need to do this in the future.