Exemplo n.º 1
0
        /// <summary>
        /// Runs new process
        /// </summary>
        /// <param name="stdOutput">If true, StandardOutput and StandardError is accessable from </param>
        /// <returns>True if process was prepared and started, false if not.</returns>
        public bool RunNewProcess(bool stdOutput = false, bool stdError = false, bool stdInput = false)
        {
            bool isProcessPrepared = PrepareBashProcess(stdOutput, stdError, stdInput);

            if (isProcessPrepared)
            {
                CurrentBashProcess.Exited += CurrentBashProcess_Exited;

                SetStateAfterProcessStarted(CurrentBashProcess.Start());

                if (IsProcessRunning)
                {
                    if (stdOutput && SubscribeStandardOutput)
                    {
                        CurrentBashProcess.BeginOutputReadLine();
                    }

                    if (stdError && SubscribeStandardError)
                    {
                        CurrentBashProcess.BeginErrorReadLine();
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Kill current process and unsubscribe events
        /// </summary>
        public void KillProcess()
        {
            CurrentBashProcess.Exited -= CurrentBashProcess_Exited;

            CurrentBashProcess.Kill();
            CurrentBashProcess.WaitForExit();

            ExitedOrKilledProcessAction(true);

            CurrentBashProcess.Dispose();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Waits for process finish or terminate after processTimeout
        /// </summary>
        /// <param name="processTimeout">Time (in ms) to wait before SIGHTERM proces. If 0, process won't be killed - method will wait for exit</param>
        private void WaitForFinish(int processTimeout)
        {
            if (processTimeout > 0)
            {
                bool isExited = CurrentBashProcess.WaitForExit(processTimeout);

                if (!isExited)
                {
                    CurrentBashProcess.Kill();
                }
            }
            else
            {
                CurrentBashProcess.WaitForExit();
            }
        }