I'm getting ready to write an online judge,
A program that can compile user code and run a program to check the answer, like an online judge uva.
And I had a problem in catching an exception from the sending program, as shown below.
int main() { while(~scanf("%d %d",n,&m)) { printf("%d\n",n+m); } return 0; }
its access is denied in the first line because it scans an integer for the error position.
How can I catch a runtime error for my process?
I used "try catch" to catch the exception,
but he did not respond to a runtime error.
therefore, I only check the exit code of the sending program, although this is not a good method to verify, other than the process.
and it looks like photo
I need to close the error message box manually,
and I find a solution that should use the SEH DLL handler for the process.
SetErrorMode(SEM_NOGPFAULTERRORBOX);
but I don't know how to use it in a C # process.
and below my code of judgment
timer = new Stopwatch(); timer.Reset(); submitProg = new Process(); submitProg.StartInfo.FileName = outputFile; submitProg.StartInfo.UseShellExecute = false; submitProg.StartInfo.CreateNoWindow = true; submitProg.StartInfo.RedirectStandardInput = true; submitProg.StartInfo.RedirectStandardOutput = true; submitProg.StartInfo.RedirectStandardError = true; submitProg.StartInfo.ErrorDialog = false; submitProg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; submitProg.EnableRaisingEvents = true; submitProg.Start(); timer.Start(); progInput = submitProg.StandardInput; progOutput = submitProg.StandardOutput; progInput.Write(inputStream.ReadToEnd()); submitProg.StandardInput.Close(); while (!submitProg.HasExited) { peakPagedMem = submitProg.PeakPagedMemorySize64; peakVirtualMem = submitProg.PeakVirtualMemorySize64; peakWorkingSet = submitProg.PeakWorkingSet64; if (peakPagedMem > memLimit) { submitProg.Kill(); } if (timer.ElapsedMilliseconds > timeLimit) { timeLimitExceed = true; submitProg.Kill(); } } timeUsed = timer.ElapsedMilliseconds; timer.Stop(); if(submitProg.ExitCode!=0)systemRuntimeError = true;
Thank you for helping, and so sorry for my poor English.
====================================
PS
the question is how can I set the error mode for a child process in C #.
My English is not good enough to explain the problem, so sorry. <(_ _)>