示例#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);
        }
示例#2
0
 //java
 public static string GetJavaFilePath()
 {
     return(Directories.GetMainDir() + PathFormat + JavaFileName + JavaFileType);
 }
示例#3
0
        public static string[] GetRunJavaCommands(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 = "java Main < " + '"' + Path + @"\" + File.Name + '"' + " > " + '"' + Directories.GetOutDir() + @"\" + Temp + OutType + '"';
                Commands[i++] = Command;
            }
            return(Commands);
        }