Esempio n. 1
0
 public AsyncLineReader(AsyncStreamReader sr)
 {
     _streamReader           = sr;
     _streamReader.DataRead += StreamReaderDataRead;
     Encoding = Encoding.Default;
 }
Esempio n. 2
0
        public void Start()
        {
            if (IsRunning)
            {
                throw new ApplicationException("already running.");
            }

            _wasClosed = false;

            _process = new Process();
            _process.StartInfo.FileName = this.AppFileName;
            if (Arguments != null)
            {
                _process.StartInfo.Arguments = Arguments;
            }
            if (WorkingDirectory != null)
            {
                _process.StartInfo.WorkingDirectory = WorkingDirectory;
            }
            _process.StartInfo.RedirectStandardInput  = true;
            _process.StartInfo.RedirectStandardOutput = ModeStdout != CommunicationMode.None;
            _process.StartInfo.RedirectStandardError  = ModeStderr != CommunicationMode.None;
            _process.StartInfo.UseShellExecute        = false;
            _process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            _process.StartInfo.CreateNoWindow         = true;


            if (ModeStderr == CommunicationMode.None && ModeStdout == CommunicationMode.None)
            {
                _process.Exited += _process_Exited;
                _process.EnableRaisingEvents = true;
            }


            _process.Start();
            ProcessId = _process.Id;
            try { _process.PriorityClass = PriorityClass; }
            catch
            {
            }


            // Stderr
            if (ModeStderr != CommunicationMode.None)
            {
                _stderrReader           = new AsyncStreamReader(_process.StandardError.BaseStream, BufferSizeStderr);
                _stderrReader.DataRead += _stderrReader_DataRead;
            }
            if (ModeStderr == CommunicationMode.Line)
            {
                _stderrLineReader = new AsyncLineReader(_stderrReader);
                if (Encoding != null)
                {
                    _stderrLineReader.Encoding = Encoding;
                }
                _stderrLineReader.LineRead += _stderrLineReader_LineRead;
            }

            // Stdout
            if (ModeStdout != CommunicationMode.None)
            {
                _stdoutReader           = new AsyncStreamReader(_process.StandardOutput.BaseStream, BufferSizeStdout);
                _stdoutReader.DataRead += _stdoutReader_DataRead;
            }
            if (ModeStdout == CommunicationMode.Line)
            {
                _stdoutLineReader = new AsyncLineReader(_stdoutReader);
                if (Encoding != null)
                {
                    _stdoutLineReader.Encoding = Encoding;
                }
                _stdoutLineReader.LineRead += _stdoutLineReader_LineRead;
            }

            if (ModeStderr != CommunicationMode.None)
            {
                _stderrReader.Begin();
            }
            if (ModeStdout != CommunicationMode.None)
            {
                _stdoutReader.Begin();
            }
        }
Esempio n. 3
0
 public AsyncLineReader(AsyncStreamReader sr)
 {
     _streamReader = sr;
     _streamReader.DataRead += StreamReaderDataRead;
     Encoding = Encoding.Default;
 }