Пример #1
0
        internal static Process StartProcessInWindow(string fileName, string args)
        {
            var     serviceDir      = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Process ExternalProcess = new Process();

            ExternalProcess.StartInfo.FileName        = "cmd";
            ExternalProcess.StartInfo.Arguments       = $"/c {fileName} {args}";
            ExternalProcess.StartInfo.UseShellExecute = false;
            //ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            ExternalProcess.StartInfo.WorkingDirectory = serviceDir;
            //ExternalProcess.StartInfo.RedirectStandardInput = true;
            //ExternalProcess.StartInfo.RedirectStandardOutput = true;
            //ExternalProcess.StartInfo.RedirectStandardError = true;
            //ExternalProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;

            //ExternalProcess.ErrorDataReceived += errorDataHandler;

            ExternalProcess.StartInfo.CreateNoWindow = false;
            ExternalProcess.Start();

            //Add process to job object to make sure it is closed if the engine crashes without
            //calling the exit code.
            ChildProcessTracker.AddProcess(ExternalProcess);

            ExternalProcess.EnableRaisingEvents = true;
            //ExternalProcess.BeginErrorReadLine();

            AppDomain.CurrentDomain.ProcessExit += (x, y) => CurrentDomain_ProcessExit(x, y, ExternalProcess);

            return(ExternalProcess);
        }
Пример #2
0
        internal static Process StartProcessInBackgroundWithRedirects(
            string fileName,
            string args,
            EventHandler exitCallback = null,
            DataReceivedEventHandler errorDataHandler = null)
        {
            var     pluginDir       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Process ExternalProcess = new Process();

            ExternalProcess.StartInfo.FileName        = "cmd";
            ExternalProcess.StartInfo.Arguments       = $"/c {fileName} {args}";
            ExternalProcess.StartInfo.UseShellExecute = false;
            //ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

            ExternalProcess.StartInfo.WorkingDirectory       = pluginDir;
            ExternalProcess.StartInfo.RedirectStandardInput  = true;
            ExternalProcess.StartInfo.RedirectStandardOutput = true;
            ExternalProcess.StartInfo.RedirectStandardError  = true;
            ExternalProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;

            //Async error data handler is used for tracking progress
            if (errorDataHandler != null)
            {
                ExternalProcess.ErrorDataReceived += errorDataHandler;
            }
            else
            {
                ExternalProcess.ErrorDataReceived += defaultErrorDataHandler;
            }

            ExternalProcess.StartInfo.CreateNoWindow = true;

            if (exitCallback != null)
            {
                ExternalProcess.Exited += exitCallback;
            }

            ExternalProcess.Start();

            //Add process to job object to make sure it is closed if the engine crashes without
            //calling the exit code.
            ChildProcessTracker.AddProcess(ExternalProcess);

            ExternalProcess.EnableRaisingEvents = true;
            ExternalProcess.BeginErrorReadLine();

            ExternalProcess.StandardInput.AutoFlush = true;

            AppDomain.CurrentDomain.ProcessExit += (x, y) => CurrentDomain_ProcessExit(x, y, ExternalProcess);

            return(ExternalProcess);
        }