public static Result ProcessRunJava(string command)
        {
            Process          process   = new Process();          //khoi tao process
            Result           result    = new Result();           //khoi tao doi tuong de luu tru ket qua tu process
            ProcessStartInfo StartInfo = new ProcessStartInfo(); //khoi tao info chay cho process

            StartInfo.FileName = "cmd.exe";
            //StartInfo.Arguments = "/-cp "+'"' + Directories.GetMainDir() +'"' +" "+"Main";
            StartInfo.Arguments             = Carries + "cd " + '"' + Directories.GetMainDir() + '"' + "&" + command;
            StartInfo.UseShellExecute       = false;
            StartInfo.CreateNoWindow        = true;
            StartInfo.RedirectStandardError = true;
            //StartInfo.RedirectStandardInput = true;
            //StartInfo.RedirectStandardOutput = true;
            process.StartInfo = StartInfo;
            process.Start();//chay process
            /*doc input*/
            //streamwriter sw = process.standardinput;
            //streamreader sr = process.standardoutput;
            //sw.writeline(fileinputcontent);
            //sw.close();
            /*kiem tra thoi gian chay*/
            Boolean TimeLimit = process.WaitForExit(Time);

            if (TimeLimit == false)
            {
                if (!process.HasExited)
                {
                    process.Kill();
                    foreach (var child in Process.GetProcessesByName("java"))
                    {
                        child.Kill();
                    }
                }
                result.Error = "Time Limit Exceeded";
                return(result);
            }
            /*luu ket qua*/
            //result.Output = sr.ReadToEndAsync().ToString();
            //sr.Close();
            result.Error = process.StandardError.ReadToEnd();
            return(result);
        }
        public static string ProcessCompileCSharp()
        {
            Regex            reg       = new Regex(@"(?<error>Main.cs.*)");
            Process          process   = new Process();          //khoi tao process
            ProcessStartInfo startInfo = new ProcessStartInfo(); //khoi tao info chay cho process

            startInfo.FileName  = "cmd.exe";
            startInfo.Arguments = Carries + "cd " + '"' + Directories.GetMainDir() + '"' + "&" + '"' + StartupPath + '"' + " " + "Main.cs";
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            process.StartInfo = startInfo;
            process.Start();//chay process
            /*luu ket qua*/
            string error  = "";
            string result = "";

            error = process.StandardOutput.ReadToEnd();
            foreach (Match item in reg.Matches(error))
            {
                result += item.Groups["error"].ToString();
            }
            return(result);
        }
示例#3
0
 public static string GetCSharpFilePath()
 {
     return(Directories.GetMainDir() + PathFormat + FileName + CSharpFileType);
 }
示例#4
0
        public static string[] GetRunCSharpCommands(string Path)
        {
            string OutType = TextFileType;

            if (customFileType.Equals(OutputFileType))
            {
                OutType = OutputFileType;
            }
            if (customFileType.Equals(AnswerFileType))
            {
                OutType = AnswerFileType;
            }
            DirectoryInfo Dir = new DirectoryInfo(Path);

            string[] Commands = new string[Dir.GetFiles().Length];
            int      i        = 0;

            foreach (FileInfo File in Dir.GetFiles())
            {
                int    Index   = File.Name.LastIndexOf('.');
                string Temp    = File.Name.Substring(0, Index);
                string Command = "Main < " + '"' + Path + @"\" + File.Name + '"' + " > " + '"' + Directories.GetOutDir() + @"\" + Temp + OutType + '"';
                Commands[i++] = Command;
            }
            return(Commands);
        }