I am a programming teacher and I am developing an automated checker for the students HWs (All are Console Apps). Basically, I run the student code using some Process.Start() (with some input file) and check if its output is as expected. If, for some reason, the student code did no complete succesfully, I send them the exception thrown by their code using the process Standart Error redirection.
However, I want to do better then that. I want to find the input line written to the process StandartInput afterwhich their exception took place. How can I do that? My current code is more or less:
ProcessStartInfo psi = new ProcessStartInfo(students_exe_path);
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
String randomInputFile = randomInputFilesFolder + "\\" + "test.txt";
psi.WorkingDirectory = randomInputFilesFolder;
Process p = Process.Start(psi);
StreamWriter inputWriter = p.StandardInput;
String[] inputLines = File.ReadAllLines(randomInputFile);
foreach (String line in inputLines)
{
// here I wanted to read the standart error so far (before writing next input line)
String errorTextBefore = p.StandardError.ReadToEnd(); // can not use this because blocks progress.
inputWriter.WriteLine(line); // sending next input line to students app
// here I wanted to read the standart error so far (after writing next input line)
String errorTextAfter = p.StandardError.ReadToEnd(); // can not use because blocks
if (errorTextBefore != errorTextAfter) Console.WriteLine("Line {0} caused the exception",line);
}
Or maybe I can check from p.StandartInput which text was not "consumed" by the process?
Tamir