Пример #1
0
        /// <summary>
        /// Run the process and get the output without deadlocks.
        /// </summary>
        /// <param name="command">The name or path of the command.</param>
        /// <param name="parameters">The parameters of the command.</param>
        /// <returns>The outputs.</returns>
        public static ProcessOutputs RunProcessAndGetOutput(string command, string parameters)
        {
            var outputs = new ProcessOutputs();
            var adbProcess = Process.Start(
                new ProcessStartInfo(command, parameters)
                {
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                });
            adbProcess.OutputDataReceived += (_, args) => LockProcessAndAddDataToList(adbProcess, outputs.OutputLines, args);
            adbProcess.ErrorDataReceived += (_, args) => LockProcessAndAddDataToList(adbProcess, outputs.OutputErrors, args);
            adbProcess.BeginOutputReadLine();
            adbProcess.BeginErrorReadLine();
            adbProcess.WaitForExit();

            outputs.ExitCode = adbProcess.ExitCode;

            return outputs;
        }
Пример #2
0
        /// <summary>
        /// Run the process and get the output without deadlocks.
        /// </summary>
        /// <param name="command">The name or path of the command.</param>
        /// <param name="parameters">The parameters of the command.</param>
        /// <returns>The outputs.</returns>
        public static ProcessOutputs RunProcessAndGetOutput(string command, string parameters)
        {
            var outputs    = new ProcessOutputs();
            var adbProcess = Process.Start(
                new ProcessStartInfo(command, parameters)
            {
                UseShellExecute        = false,
                CreateNoWindow         = true,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
            });

            adbProcess.OutputDataReceived += (_, args) => LockProcessAndAddDataToList(adbProcess, outputs.OutputLines, args);
            adbProcess.ErrorDataReceived  += (_, args) => LockProcessAndAddDataToList(adbProcess, outputs.OutputErrors, args);
            adbProcess.BeginOutputReadLine();
            adbProcess.BeginErrorReadLine();
            adbProcess.WaitForExit();

            outputs.ExitCode = adbProcess.ExitCode;

            return(outputs);
        }