예제 #1
0
        private void InternalStart(params string[] arguments)
        {
            if (IsRunning)
            {
                throw new InvalidOperationException("The running process must first exit.");
            }


            _isRunning = true;

            _mreProcessExit.Reset();
            _mreOutputDone.Reset();
            _mreErrorDone.Reset();
            _exitCode = 0;
            _stdIn    = null;
            _running  = new Process();

            string stringArgs = "";

            if (_autoEscape)
            {
                stringArgs = ArgumentList.EscapeArguments(arguments);
            }
            else
            {
                stringArgs = ArgumentList.DoNotEscapeArguments(arguments);
            }

            ProcessStartInfo psi = new ProcessStartInfo(_executable, stringArgs);

            psi.WorkingDirectory = this.WorkingDirectory;

            psi.RedirectStandardInput  = true;
            psi.RedirectStandardError  = true;
            psi.RedirectStandardOutput = true;
            psi.CreateNoWindow         = true;
            psi.UseShellExecute        = false;
            psi.ErrorDialog            = false;

            _running.StartInfo = psi;

            _running.Exited             += process_Exited;
            _running.OutputDataReceived += process_OutputDataReceived;
            _running.ErrorDataReceived  += process_ErrorDataReceived;

            _running.EnableRaisingEvents = true;
            Trace.TraceInformation("EXEC: {0} {1}", _running.StartInfo.FileName, _running.StartInfo.Arguments);
            _running.Start();

            _stdIn = _running.StandardInput;
            _running.BeginOutputReadLine();
            _running.BeginErrorReadLine();
        }
예제 #2
0
        /// <summary> Returns a debug-view string of process/arguments to execute </summary>
        public override string ToString()
        {
            string stringArguments = "";

            if (_autoEscape)
            {
                stringArguments = ArgumentList.EscapeArguments(_arguments);
            }
            else
            {
                stringArguments = ArgumentList.DoNotEscapeArguments(_arguments);
            }

            return(String.Format("{0} {1}", _executable, stringArguments));
        }