public static (string execFileOutput, bool ExecutedNoErrors, string errorOnExecution) executeFile(string myFileToExec, string hest2Test) { string JavaComp = "java.exe"; string PythonComp = "python.exe"; string compilerUsed = ""; string inputToPassHest2 = ""; string hest2TestIput = FilesTool.processFileOutPut(hest2Test); if (Path.GetExtension(myFileToExec).Equals(".exe")) { compilerUsed = myFileToExec; inputToPassHest2 = hest2TestIput; } else if (Path.GetExtension(myFileToExec).Equals(".py")) { compilerUsed = PythonComp; inputToPassHest2 = hest2TestIput; } else { compilerUsed = JavaComp; inputToPassHest2 = hest2TestIput; } using (Process myProcess = new Process()) { myProcess.StartInfo.FileName = compilerUsed; myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.RedirectStandardError = true; myProcess.StartInfo.RedirectStandardInput = true; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.CreateNoWindow = true; string javaArgs = $" -classpath {Path.GetDirectoryName(myFileToExec)} {Path.GetFileNameWithoutExtension(myFileToExec)}"; myProcess.StartInfo.Arguments = javaArgs; myProcess.Start(); StreamWriter myStreamWriter = myProcess.StandardInput; myStreamWriter.WriteLine(hest2TestIput); string devOUT = myProcess.StandardOutput.ReadToEnd(); string debuggError = myProcess.StandardError.ReadToEnd(); if (devOUT.Length > 0) { return(execFileOutput : devOUT, ExecutedNoErrors : true, errorOnExecution : debuggError); } else { return(execFileOutput : devOUT, ExecutedNoErrors : false, errorOnExecution : debuggError); } } }
private void executeGivenFiles(int caseSwitch) { /// <summary>method <c>draw</c> renders the point.</summary> OrderedFiles myOrderedFiles = new OrderedFiles(); myOrderedFiles = LanguageRecognizion.classifierProgLang(FilesTool.filesToCheck); int counterIDSstudensHest1 = 0; switch (caseSwitch) { case 1: foreach (string item in myOrderedFiles.cFiles) { string lastFolderNameStudenID = Path.GetFileName(Path.GetDirectoryName(item.ToString())); string IdNumberStuden = Path.GetFileNameWithoutExtension(item); if (isHest1) { (string compilerOutPutComp, bool compiledOk, string compiledFileToCheck) = FilesExecuterHest1.compileFile(item); if (compiledOk) { (string compilerOutPutExec, string execFileOutput, bool compiledSuccsesfully) = FilesExecuterHest1.executeFile(compiledFileToCheck); RevisionResultCfilesHest1.Add(new FileResultHest1(execFileOutput, compiledSuccsesfully, compilerOutPutExec, item, FilesTool.studentIDS[counterIDSstudensHest1], "Kinneret Computer Science")); counterIDSstudensHest1++; } else { RevisionResultCfilesHest1.Add(new FileResultHest1("None", compiledOk, compilerOutPutComp, item, FilesTool.studentIDS[counterIDSstudensHest1], "CS Kinneret")); counterIDSstudensHest1++; } } else //HEST2 { //(string compilerOutPut, string execFileOutput) = FilesExecuterHest2.executeFile(item, textBox1InputParameters.Text); //.executeFile(item); // MessageBox.Show($"Compiler out put:{compilerOutPut} \n\n exeFileOutPut:{execFileOutput}"); //RevisionResultCfilesHest1.Add(new FileResultHest1(compilerOutPut, execFileOutput, textBoxHEST2ExpectedOutPut.Text)); (string OutputFromFile, bool wasSuccessfull, string CompiledFilePath) = FilesExecuterHest2.compileFile(item); if (wasSuccessfull) { foreach (string inputCheck in FilesTool.inputToBeCheckedHest2) { //string s = FilesTool.processFileOutPut(inputCheck); (string execOutput, bool hasErrors, string ErrorsOnExec) = FilesExecuterHest2.executeFile(CompiledFilePath, inputCheck); (bool PassedTEstHest2, string ExpectedTestOutPut) = FilesTool.PassedHest2Test(execOutput, inputCheck); //bool PassedTEstHest2 RevisionResultCfilesHest2.Add(new FileResultHest2(execOutput, hasErrors, ErrorsOnExec, PassedTEstHest2, Path.GetFileName(inputCheck), item, FilesTool.studentIDS[counterIDSstudensHest1], ExpectedTestOutPut, "Computer Science")); counterIDSstudensHest1++; } } else { RevisionResultCfilesHest2.Add(new FileResultHest2("none", wasSuccessfull, OutputFromFile, false, "none", item, FilesTool.studentIDS[counterIDSstudensHest1], "None", "Computer Science")); counterIDSstudensHest1++; } } } break; case 2: foreach (string item in myOrderedFiles.javaFiles) { string lastFolderNameStudenID = Path.GetFileName(Path.GetDirectoryName(item.ToString())); string IdNumberStuden = Path.GetFileNameWithoutExtension(item); if (isHest1) { (string compilerOutPutComp, bool compiledOk, string compiledFileToCheck) = FilesExecuterHest1.compileFile(item); if (compiledOk) { (string compilerOutPutExec, string execFileOutput, bool compiledSuccsesfully) = FilesExecuterHest1.executeFile(compiledFileToCheck); RevisionResultJavaFilesHest1.Add(new FileResultHest1(execFileOutput, compiledSuccsesfully, compilerOutPutExec, item, FilesTool.studentIDS[counterIDSstudensHest1], "Kinneret Computer Science")); counterIDSstudensHest1++; } else { RevisionResultJavaFilesHest1.Add(new FileResultHest1("None", compiledOk, compilerOutPutComp, item, FilesTool.studentIDS[counterIDSstudensHest1], "CS Kinneret")); counterIDSstudensHest1++; } } else { //(string compilerOutPut, string execFileOutput) = FilesExecuterHest2.executeFile(item, textBox1InputParameters.Text); //.executeFile(item); // MessageBox.Show($"Compiler out put:{compilerOutPut} \n\n exeFileOutPut:{execFileOutput}"); //RevisionResultCfilesHest1.Add(new FileResultHest1(compilerOutPut, execFileOutput, textBoxHEST2ExpectedOutPut.Text)); (string OutputFromFile, bool wasSuccessfull, string CompiledFilePath) = FilesExecuterHest2.compileFile(item); //(string OutputFromFile, bool wasSuccessfull, string CompiledFilePath) = FilesExecuterHest2.compileFile(itemToComp); if (wasSuccessfull) { foreach (string inputCheck in FilesTool.inputToBeCheckedHest2) { //string s = FilesTool.processFileOutPut(inputCheck); (string execOutput, bool HasNoErrors, string ErrorsOnExec) = FilesExecuterHest2.executeFile(CompiledFilePath, inputCheck); (bool PassedTEstHest2, string ExpectedTestOutPut) = FilesTool.PassedHest2Test(execOutput, inputCheck); RevisionResultJavaFilesHest2.Add(new FileResultHest2(execOutput, HasNoErrors, ErrorsOnExec, PassedTEstHest2, Path.GetFileName(inputCheck), item, FilesTool.studentIDS[counterIDSstudensHest1], ExpectedTestOutPut, "Computer Science")); } counterIDSstudensHest1++; } else { RevisionResultJavaFilesHest2.Add(new FileResultHest2("none", wasSuccessfull, OutputFromFile, false, "none", item, FilesTool.studentIDS[counterIDSstudensHest1], "None", "Computer Science")); counterIDSstudensHest1++; } } } break; case 3: foreach (string item in myOrderedFiles.pythonFiles) { string lastFolderNameStudenID = Path.GetFileName(Path.GetDirectoryName(item.ToString())); string IdNumberStuden = Path.GetFileNameWithoutExtension(item); if (isHest1) { //(string compilerOutPutExec, string execFileOutput, bool compiledSuccsesfully) = FilesExecuterHest1.executeFile(item); //RevisionResultPythonFilesHest1.Add(new FileResultHest1(execFileOutput, compiledSuccsesfully, compilerOutPutExec, item, FilesTool.studentIDS[counterIDSstudensHest1], "Cs Kinneret")); //counterIDSstudensHest1++; (string compilerOutPutComp, bool compiledOk, string compiledFileToCheck) = FilesExecuterHest1.compileFile(item); if (compiledOk) { (string compilerOutPutExec, string execFileOutput, bool compiledSuccsesfully) = FilesExecuterHest1.executeFile(compiledFileToCheck); RevisionResultPythonFilesHest1.Add(new FileResultHest1(execFileOutput, compiledSuccsesfully, compilerOutPutExec, item, FilesTool.studentIDS[counterIDSstudensHest1], "Cs Kinneret")); counterIDSstudensHest1++; } else { RevisionResultPythonFilesHest1.Add(new FileResultHest1("None", compiledOk, compilerOutPutComp, item, FilesTool.studentIDS[counterIDSstudensHest1], "CS kinneret")); counterIDSstudensHest1++; } } else { (string OutputFromFile, bool wasSuccessfull, string CompiledFilePath) = FilesExecuterHest2.compileFile(item); if (wasSuccessfull) { foreach (string inputCheck in FilesTool.inputToBeCheckedHest2) { (string execOutput, bool hasErrors, string ErrorsOnExec) = FilesExecuterHest2.executeFile(CompiledFilePath, inputCheck); (bool PassedTEstHest2, string ExpectedTestOutPut) = FilesTool.PassedHest2Test(execOutput, inputCheck); RevisionResultPythonFilesHest2.Add(new FileResultHest2(execOutput, hasErrors, ErrorsOnExec, PassedTEstHest2, Path.GetFileName(inputCheck), item, FilesTool.studentIDS[counterIDSstudensHest1], ExpectedTestOutPut, "Computer Science")); counterIDSstudensHest1++; } } else { RevisionResultPythonFilesHest2.Add(new FileResultHest2("none", wasSuccessfull, OutputFromFile, false, "none", item, FilesTool.studentIDS[counterIDSstudensHest1], "None", "Computer Science")); counterIDSstudensHest1++; } } } break; default: Console.WriteLine("Error, contact support"); break; } }