Exemple #1
0
        /// <summary>
        /// starts a new process and executes a command
        /// </summary>
        /// <param name="shell">The command to be executed.</param>
        /// <param name="arguments">The arguments of the command.</param>
        /// <param name="writerCallback">The callback to process the input.</param>
        /// <param name="doneCallback">The callback to process the output.</param>
        public static void ExecuteCommands(string shell, string arguments, StreamWriterCallback writerCallback, ProcessDoneCallback doneCallback)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object data)
            {
                ProcessStartInfo start       = new ProcessStartInfo();
                start.FileName               = shell;
                start.Arguments              = arguments;
                start.CreateNoWindow         = true;
                start.UseShellExecute        = false;
                start.RedirectStandardOutput = true;
                start.RedirectStandardInput  = true;

                string result = string.Empty;

                using (Process process = Process.Start(start))
                {
                    using (StreamWriter writer = process.StandardInput)
                    {
                        writerCallback(writer);
                    }

                    using (StreamReader reader = process.StandardOutput)
                    {
                        result = reader.ReadToEnd();
                    }

                    process.WaitForExit();
                    doneCallback(result, process.ExitCode);
                }
            }));
        }
Exemple #2
0
        /// <summary>
        /// starts a new process and executes a command
        /// </summary>
        /// <param name="shell">The command to be executed.</param>
        /// <param name="arguments">The arguments of the command.</param>
        /// <param name="writerCallback">The callback to process the input.</param>
        /// <param name="doneCallback">The callback to process the output.</param>
        public static void ExecuteCommands(string shell, string arguments, StreamWriterCallback writerCallback, ProcessDoneCallback doneCallback)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object data)
            {
                ProcessStartInfo start = new ProcessStartInfo();
                start.FileName = shell;
                start.Arguments = arguments;
                start.CreateNoWindow = true;
                start.UseShellExecute = false;
                start.RedirectStandardOutput = true;
                start.RedirectStandardInput = true;

                string result = string.Empty;

                using (Process process = Process.Start(start))
                {
                    using (StreamWriter writer = process.StandardInput)
                    {
                        writerCallback(writer);
                    }

                    using (StreamReader reader = process.StandardOutput)
                    {
                        result = reader.ReadToEnd();
                    }

                    process.WaitForExit();
                    doneCallback(result, process.ExitCode);
                }
            }));
        }