Ejemplo n.º 1
0
        /// <summary>
        /// Runs a command
        /// </summary>
        /// <param name="command">The command to run</param>
        /// <param name="args">Arguments to the command</param>
        /// <returns>The output from the command</returns>
        public string RunCommand(string command, string args)
        {
            if (command == "svn")
            {
                command = Path.GetFullPath(Path.Combine(ProjectBase, "..\\..\\imports\\release\\bin\\svn.exe"));
            }

            //System.Diagnostics.Trace.Assert(File.Exists(command), "Command exists");

            ProcessStartInfo psi = new ProcessStartInfo(command, args);

            psi.CreateNoWindow         = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            psi.UseShellExecute        = false;

            Process proc = Process.Start(psi);

            //Console.WriteLine( proc.MainModule.FileName );

            ProcessReader outreader = new ProcessReader(proc.StandardOutput);
            ProcessReader errreader = new ProcessReader(proc.StandardError);

            outreader.Start();
            errreader.Start();

            proc.WaitForExit();

            outreader.Wait();
            errreader.Wait();

            if (proc.ExitCode != 0)
            {
                throw new ApplicationException("command exit code was " +
                                               proc.ExitCode.ToString() +
                                               Environment.NewLine + errreader.Output + Environment.NewLine +
                                               "Command was " +
                                               proc.StartInfo.FileName + " " + proc.StartInfo.Arguments);
            }


            // normalize newlines
            string[] lines = Regex.Split(outreader.Output, @"\r?\n");
            return(String.Join(Environment.NewLine, lines));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs a command
        /// </summary>
        /// <param name="command">The command to run</param>
        /// <param name="args">Arguments to the command</param>
        /// <returns>The output from the command</returns>
        public string RunCommand(string command, string args)
        {
            Process proc = new Process();

            proc.StartInfo.FileName               = command;
            proc.StartInfo.Arguments              = args;
            proc.StartInfo.CreateNoWindow         = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;
            proc.StartInfo.UseShellExecute        = false;

            proc.Start();

            //Console.WriteLine( proc.MainModule.FileName );

            ProcessReader outreader = new ProcessReader(proc.StandardOutput);
            ProcessReader errreader = new ProcessReader(proc.StandardError);

            outreader.Start();
            errreader.Start();

            proc.WaitForExit();

            outreader.Wait();
            errreader.Wait();

            if (proc.ExitCode != 0)
            {
                throw new ApplicationException("command exit code was " +
                                               proc.ExitCode.ToString() +
                                               Environment.NewLine + errreader.Output + Environment.NewLine +
                                               "Command was " +
                                               proc.StartInfo.FileName + " " + proc.StartInfo.Arguments);
            }


            // normalize newlines
            string[] lines = Regex.Split(outreader.Output, @"\r?\n");
            return(String.Join(Environment.NewLine, lines));
        }