Ejemplo n.º 1
0
        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)
            {
                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);
        }
Ejemplo n.º 2
0
 //java
 public static string GetJavaFilePath()
 {
     return(Directories.GetMainDir() + PathFormat + JavaFileName + JavaFileType);
 }