Beispiel #1
0
        public void Start()//synchronized
        {
            if (RunnerInfo == null || RunnerInfo.Cmd == null || RunnerInfo.TimeLimit == 0 || RunnerInfo.MemoryLimit == 0 || RunnerInfo.Cmd == null)
            {
                throw new Exception("Missing arguments");
            }
            Process Process = new Process();

            Process.StartInfo.FileName               = RunnerInfo.CenaCoreDirectory;
            Process.StartInfo.Arguments              = String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\" \"{8}\"", RunnerInfo.Cmd.Trim('\"'), RunnerInfo.StdInFile == null ? "NULL" : RunnerInfo.StdInFile.Trim('\"'), RunnerInfo.StdOutFile == null ? "NULL" : RunnerInfo.StdOutFile.Trim('\"'), RunnerInfo.StdErrFile == null ? "NULL" : RunnerInfo.StdErrFile.Trim('\"'), RunnerInfo.TimeLimit, RunnerInfo.MemoryLimit, RunnerInfo.HighPriorityTime, RunnerInfo.APIHook == null?"NULL":RunnerInfo.APIHook.Trim('\"'), RunnerInfo.XmlFile == null ? "NULL" : RunnerInfo.XmlFile.Trim('\"'));
            Process.StartInfo.CreateNoWindow         = true;
            Process.StartInfo.UseShellExecute        = false;
            Process.StartInfo.RedirectStandardOutput = true;
            foreach (var ev in EnvironmentVariables)
            {
                if (Process.StartInfo.EnvironmentVariables[ev.Key] == null)
                {
                    Process.StartInfo.EnvironmentVariables[ev.Key] = ev.Value;
                }
                else
                {
                    Process.StartInfo.EnvironmentVariables[ev.Key] += ";" + ev.Value;
                }
            }
            if (RunnerInfo.WorkingDirectory != null)
            {
                Process.StartInfo.WorkingDirectory = RunnerInfo.WorkingDirectory;
            }
            if (Process.StartInfo.EnvironmentVariables["Path"] == null)
            {
                Process.StartInfo.EnvironmentVariables["Path"] = RunnerInfo.WorkingDirectory;
            }
            else
            {
                Process.StartInfo.EnvironmentVariables["Path"] += ";" + RunnerInfo.WorkingDirectory;
            }
            if (Identity.UserName != null)
            {
                Process.StartInfo.UserName = Identity.UserName;
                Process.StartInfo.Password = Identity.secPassword;
            }
            Process.Start();
            Process.WaitForExit(2 * RunnerInfo.TimeLimit + 1000);
            try
            {
                if (!Process.HasExited)
                {
                    RunnerInfo.KillProcessTree = true;
                }
                Process.Kill();
                if (RunnerInfo.KillProcessTree)
                {
                    try
                    {
                        ProcessesTreeKiller ptk = new ProcessesTreeKiller();
                        ptk.FindAndKillProcess(Process.Id);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    Process.Kill();
                }
            }
            catch { }
            xmlresult = Process.StandardOutput.ReadToEnd();
        }
Beispiel #2
0
        //synchronized
        public void Start()
        {
            if (RunnerInfo == null || RunnerInfo.Cmd == null || RunnerInfo.TimeLimit == 0 || RunnerInfo.MemoryLimit == 0 || RunnerInfo.Cmd == null)
                throw new Exception("Missing arguments");
            Process Process = new Process();
            Process.StartInfo.FileName = RunnerInfo.CenaCoreDirectory;
            Process.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\" \"{8}\"", RunnerInfo.Cmd.Trim('\"'), RunnerInfo.StdInFile == null ? "NULL" : RunnerInfo.StdInFile.Trim('\"'), RunnerInfo.StdOutFile == null ? "NULL" : RunnerInfo.StdOutFile.Trim('\"'), RunnerInfo.StdErrFile == null ? "NULL" : RunnerInfo.StdErrFile.Trim('\"'), RunnerInfo.TimeLimit, RunnerInfo.MemoryLimit, RunnerInfo.HighPriorityTime, RunnerInfo.APIHook==null?"NULL":RunnerInfo.APIHook.Trim('\"'), RunnerInfo.XmlFile == null ? "NULL" : RunnerInfo.XmlFile.Trim('\"'));
            Process.StartInfo.CreateNoWindow = true;
            Process.StartInfo.UseShellExecute = false;
            Process.StartInfo.RedirectStandardOutput = true;
            foreach(var ev in EnvironmentVariables)
            {
                if (Process.StartInfo.EnvironmentVariables[ev.Key]==null)
                    Process.StartInfo.EnvironmentVariables[ev.Key] = ev.Value;
                else
                    Process.StartInfo.EnvironmentVariables[ev.Key]+=";"+ev.Value;
            }
            if (RunnerInfo.WorkingDirectory != null)
                Process.StartInfo.WorkingDirectory = RunnerInfo.WorkingDirectory;
            if (Process.StartInfo.EnvironmentVariables["Path"] == null)
                Process.StartInfo.EnvironmentVariables["Path"] = RunnerInfo.WorkingDirectory;
            else
                Process.StartInfo.EnvironmentVariables["Path"] += ";" + RunnerInfo.WorkingDirectory;
            if (Identity.UserName != null)
            {
                Process.StartInfo.UserName = Identity.UserName;
                Process.StartInfo.Password = Identity.secPassword;
            }
            Process.Start();
            Process.WaitForExit(2 * RunnerInfo.TimeLimit + 1000);
            try
            {
                if (!Process.HasExited) RunnerInfo.KillProcessTree = true;
                Process.Kill();
                if (RunnerInfo.KillProcessTree)
                {
                    try
                    {
                        ProcessesTreeKiller ptk = new ProcessesTreeKiller();
                        ptk.FindAndKillProcess(Process.Id);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    Process.Kill();
                }

            }
            catch { }
            xmlresult = Process.StandardOutput.ReadToEnd();
        }