Exemple #1
0
 /// <summary>
 /// Start the process synchronously, catch the exceptions
 /// </summary>
 public bool TryDoWait(bool hidden = false)
 {
     try {
         return(DoWait(hidden));
     } catch (Exception e) {
         ErrorOutput.AppendLine(e.Message);
         return(false);
     }
 }
Exemple #2
0
        /// <summary>
        /// Start the process synchronously
        /// </summary>
        public bool DoWait(bool hidden = false)
        {
            StandardOutput.Clear();
            ErrorOutput.Clear();

            if (hidden)
            {
                StartInfo.CreateNoWindow = true;
                StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            }

            if (!string.IsNullOrEmpty(Arguments))
            {
                StartInfo.Arguments = Arguments;
            }

            if (_nbExecution > 0)
            {
                Kill();
            }

            _nbExecution++;

            if (_process == null)
            {
                _process = new Process {
                    StartInfo = StartInfo
                };
                _process.OutputDataReceived += (sender, args) => StandardOutput.AppendLine(args.Data);
                _process.ErrorDataReceived  += (sender, args) => ErrorOutput.AppendLine(args.Data);
            }

            _process.Start();
            _process.WaitForExit();

            ExitCode = _process.ExitCode;

            return(ExitCode == 0);
        }