Пример #1
0
        public void WritelnStringToProcess(string id, string data)
        {
            Utils.ProcessRunner pr = StartedProcesses[id] as Utils.ProcessRunner;

            if (pr == null)
            {
                string files = "";
                foreach (string key in StartedProcesses.Keys)
                {
                    files += key + " ";
                }
                throw new Exception("pr = null: " + id + " Count = " + StartedProcesses.Count + " Files " + files);
            }
            if (pr.process == null)
            {
                throw new Exception("pr.process = null");
            }
            if (pr.process.StandardInput == null)
            {
                throw new Exception("pr.process.StandardInput = null");
            }
            if (pr.process.StandardInput.BaseStream == null)
            {
                throw new Exception("pr.process.StandardInput.BaseStream = null");
            }

            byte[]       buffer = InputEncoding.GetBytes(data + pr.process.StandardInput.NewLine);
            StreamObject so     = new StreamObject();

            so.stream = pr.process.StandardInput.BaseStream;
            so.text   = data + Environment.NewLine;
            so.id     = id;
            pr.process.StandardInput.BaseStream.BeginWrite(buffer, 0, buffer.Length, Write_Callback, so);
        }
Пример #2
0
 public void KillAll()
 {
     Utils.ProcessRunner[] process = new Utils.ProcessRunner[StartedProcesses.Values.Count];
     StartedProcesses.Values.CopyTo(process, 0);
     foreach (Utils.ProcessRunner pr in process)
     {
         pr.Kill();
         PRunner_ProcessExited(pr, null);
     }
 }
Пример #3
0
        public void Run(string fileName, string args, bool redirectIO, bool redirectErrors, bool RunWithPause, string WorkingDirectory, bool attachDebugger, bool fictive_attach)
        {
            Utils.ProcessRunner PRunner = new Utils.ProcessRunner();
            PRunner.ProcessExited += new EventHandler(PRunner_ProcessExited);
            //PRunner.OutputLineReceived += new Utils.LineReceivedEventHandler(PRunner_OutputLineReceived);
            PRunner.WorkingDirectory = WorkingDirectory;
            StartedProcesses.Add(fileName, PRunner);
            StartedFiles.Add(PRunner, fileName);
            string ReadSignalName = null;

            /*if (redirectIO)
             * {
             *  ReadSignalName = Path.GetFileNameWithoutExtension(fileName) + (new Random()).Next(10000).ToString();
             *  args = "READSIGNAL" + ReadSignalName + " " + args;
             *  ReadSignalNames.Add(ReadSignalName, fileName);
             *  ReadSignalNames.Add(fileName, ReadSignalName);
             *  ReadSignalList.Add(ReadSignalName);
             * }
             * if (redirectErrors)
             * {
             *  //args = "CATCHUNHANDLEDEXCEPTIONS" +" "+ args;
             * }*/
            if (Starting != null)
            {
                Starting(fileName);
            }
            try
            {
                PRunner.Start(fileName, args, redirectIO, redirectErrors, RunWithPause, attachDebugger, fictive_attach);
                if ((PRunner.TempBatFile != null) && !TempBatFiles.ContainsKey(fileName))
                {
                    TempBatFiles.Add(fileName, PRunner.TempBatFile);
                }
                if (redirectIO)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardOutput, OutputStreamId + fileName, InputEncoding);
                    PRunner.process.StandardInput.AutoFlush = true;
                }
                if (redirectErrors)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardError, ErrorStreamId + fileName, InputEncoding);
                }
            }
            catch (Exception)
            {
                RemoveFromTables(fileName);
                throw;
            }
        }
Пример #4
0
        public void WritelnStringToProcess(string id, string data)
        {
            Utils.ProcessRunner pr = StartedProcesses[id] as Utils.ProcessRunner;

            /*string s=StartedProcesses.Count.ToString()+" ";
             * foreach (string ss in StartedProcesses.Keys)
             *  s += ss + "|";
             * if (pr == null) throw new Exception("pr==null, " + id + " " + data+" started process"+s);*/
            byte[]       buffer = InputEncoding.GetBytes(data + pr.process.StandardInput.NewLine);
            StreamObject so     = new StreamObject();

            so.stream = pr.process.StandardInput.BaseStream;
            so.text   = data + Environment.NewLine;
            so.id     = id;
            pr.process.StandardInput.BaseStream.BeginWrite(buffer, 0, buffer.Length, Write_Callback, so);
        }
Пример #5
0
        public void Run(string fileName, string args, bool redirectIO, bool redirectErrors, bool RunWithPause, string WorkingDirectory, bool attachDebugger, bool fictive_attach)
        {
            Utils.ProcessRunner PRunner = new Utils.ProcessRunner();
            PRunner.ProcessExited += new EventHandler(PRunner_ProcessExited);
            //PRunner.OutputLineReceived += new Utils.LineReceivedEventHandler(PRunner_OutputLineReceived);
            PRunner.WorkingDirectory = WorkingDirectory;
            StartedProcesses.Add(fileName, PRunner);
            StartedFiles.Add(PRunner, fileName);
            string ReadSignalName = null;

            if (Starting != null)
            {
                Starting(fileName);
            }
            try
            {
                PRunner.Start(fileName, args, redirectIO, redirectErrors, RunWithPause, attachDebugger, fictive_attach);
                if ((PRunner.TempBatFile != null) && !TempBatFiles.ContainsKey(fileName))
                {
                    TempBatFiles.Add(fileName, PRunner.TempBatFile);
                }
                if (redirectIO)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardOutput, OutputStreamId + fileName, InputEncoding);
                    PRunner.process.StandardInput.AutoFlush = true;
                }
                if (redirectErrors)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardError, ErrorStreamId + fileName, InputEncoding);
                }
            }
            catch (Exception e)
            {
#if DEBUG
                File.AppendAllText("logRun.txt", e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine);
#endif
                RemoveFromTables(fileName);
                throw; // Это не перехватывается и приводит к вылету оболочки - SSM 22/04/19
            }
        }
Пример #6
0
        public void Run(string fileName, string args, bool redirectIO, bool redirectErrors, bool RunWithPause, string WorkingDirectory, bool attachDebugger, bool fictive_attach)
        {
            Utils.ProcessRunner PRunner = new Utils.ProcessRunner();
            PRunner.ProcessExited += new EventHandler(PRunner_ProcessExited);
            //PRunner.OutputLineReceived += new Utils.LineReceivedEventHandler(PRunner_OutputLineReceived);
            PRunner.WorkingDirectory = WorkingDirectory;
            StartedProcesses.Add(fileName, PRunner);
            StartedFiles.Add(PRunner, fileName);
            string ReadSignalName = null;

            if (Starting != null)
            {
                Starting(fileName);
            }
            try
            {
                PRunner.Start(fileName, args, redirectIO, redirectErrors, RunWithPause, attachDebugger, fictive_attach);
                if ((PRunner.TempBatFile != null) && !TempBatFiles.ContainsKey(fileName))
                {
                    TempBatFiles.Add(fileName, PRunner.TempBatFile);
                }
                if (redirectIO)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardOutput, OutputStreamId + fileName, InputEncoding);
                    PRunner.process.StandardInput.AutoFlush = true;
                }
                if (redirectErrors)
                {
                    EventedStreamReaderList.Add(PRunner.process.StandardError, ErrorStreamId + fileName, InputEncoding);
                }
            }
            catch (Exception)
            {
                RemoveFromTables(fileName);
                throw;
            }
        }
Пример #7
0
 public void Run(string fileName,string args,bool redirectIO,bool redirectErrors, bool RunWithPause, string WorkingDirectory, bool attachDebugger, bool fictive_attach)
 {
     Utils.ProcessRunner PRunner = new Utils.ProcessRunner();
     PRunner.ProcessExited += new EventHandler(PRunner_ProcessExited);
     //PRunner.OutputLineReceived += new Utils.LineReceivedEventHandler(PRunner_OutputLineReceived);
     PRunner.WorkingDirectory = WorkingDirectory;
     StartedProcesses.Add(fileName, PRunner);
     StartedFiles.Add(PRunner, fileName);
     string ReadSignalName=null;
     /*if (redirectIO)
     {
         ReadSignalName = Path.GetFileNameWithoutExtension(fileName) + (new Random()).Next(10000).ToString();
         args = "READSIGNAL" + ReadSignalName + " " + args;
         ReadSignalNames.Add(ReadSignalName, fileName);
         ReadSignalNames.Add(fileName, ReadSignalName);
         ReadSignalList.Add(ReadSignalName);
     }
     if (redirectErrors)
     {
         //args = "CATCHUNHANDLEDEXCEPTIONS" +" "+ args;
     }*/
     if (Starting != null)
         Starting(fileName);
     try
     {
         PRunner.Start(fileName, args, redirectIO, redirectErrors, RunWithPause, attachDebugger, fictive_attach);
         if ((PRunner.TempBatFile != null) && !TempBatFiles.ContainsKey(fileName))
             TempBatFiles.Add(fileName, PRunner.TempBatFile);
         if (redirectIO)
         {
             EventedStreamReaderList.Add(PRunner.process.StandardOutput, OutputStreamId + fileName, InputEncoding);
             PRunner.process.StandardInput.AutoFlush = true;
         }
         if (redirectErrors)
         {
             EventedStreamReaderList.Add(PRunner.process.StandardError, ErrorStreamId + fileName, InputEncoding);
         }
     }
     catch(Exception)
     {
         RemoveFromTables(fileName);
         throw;
     }
 }
Пример #8
0
 public void KillAll()
 {
     Utils.ProcessRunner[] process = new Utils.ProcessRunner[StartedProcesses.Values.Count];
     StartedProcesses.Values.CopyTo(process, 0);
     foreach (Utils.ProcessRunner pr in process)
     {
         pr.Kill();
         PRunner_ProcessExited(pr,null);
     }
 }