Exemple #1
0
        public static void StdOutDataHandler(object sendingProcess, DataReceivedEventArgs OutLine)
        {
            if (!String.IsNullOrEmpty(OutLine.Data))
            {
                string s = "  " + OutLine.Data;

                //Print( "Stdout output: " + s );

                RunStdout.Add(s);
                Print(s + "\n");
            }
        }
Exemple #2
0
        //
        // Helper functions for running other programs
        //
        public string[] Run(string ExeName, string Arguments)
        {
            Print("> " + ExeName + " " + Arguments + "\n");
            RunStdout.Clear();
            RunStderr.Clear();

            System.Diagnostics.Process p = new System.Diagnostics.Process();

            p.StartInfo.FileName               = ExeName;
            p.StartInfo.Arguments              = Arguments;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.UseShellExecute        = false; // Needed for stdout/stderr redirection
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput  = true;

            p.OutputDataReceived += new DataReceivedEventHandler(StdOutDataHandler);
            p.ErrorDataReceived  += new DataReceivedEventHandler(StdErrDataHandler);


            p.Start();
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();
            p.WaitForExit();

            //
            // Should improve this: strip trailing empty lines from both of the outputs
            //

            string [] s = new string[RunStdout.Count + RunStderr.Count];

            for (int i = 0; i < RunStdout.Count; i++)
            {
                s[i] = (string)RunStdout[i];
            }

            for (int i = 0; i < RunStderr.Count; i++)
            {
                s[i + RunStdout.Count] = (string)RunStderr[i];
            }

            return(s);
        }