예제 #1
0
파일: Executable.cs 프로젝트: robzelt/kudu
        public Tuple <string, string> Execute(string arguments, params object[] args)
#endif
        {
#if !SITEMANAGEMENT
            using (GetProcessStep(tracer, arguments, args))
            {
#endif
            var process = CreateProcess(arguments, args);
            process.Start();

#if !SITEMANAGEMENT
            var idleManager = new Kudu.Core.Infrastructure.IdleManager(IdleTimeout, tracer);
#else
            var idleManager = new Kudu.SiteManagement.IdleManager();
#endif
            Func <StreamReader, string> reader = (StreamReader streamReader) =>
            {
                var    strb   = new StringBuilder();
                char[] buffer = new char[1024];
                int    read;
                while ((read = streamReader.ReadBlock(buffer, 0, buffer.Length)) != 0)
                {
                    idleManager.UpdateActivity();
                    strb.Append(buffer, 0, read);
                }
                idleManager.UpdateActivity();
                return(strb.ToString());
            };

            IAsyncResult outputReader = reader.BeginInvoke(process.StandardOutput, null, null);
            IAsyncResult errorReader  = reader.BeginInvoke(process.StandardError, null, null);

            process.StandardInput.Close();

            idleManager.WaitForExit(process);

            string output = reader.EndInvoke(outputReader);
            string error  = reader.EndInvoke(errorReader);

#if !SITEMANAGEMENT
            tracer.TraceProcessExitCode(process);
#endif

            // Sometimes, we get an exit code of 1 even when the command succeeds (e.g. with 'git reset .').
            // So also make sure there is an error string
            if (process.ExitCode != 0)
            {
                string text = String.IsNullOrEmpty(error) ? output : error;

                throw new CommandLineException(Path, process.StartInfo.Arguments, text)
                      {
                          ExitCode = process.ExitCode,
                          Output   = output,
                          Error    = error
                      };
            }

            return(Tuple.Create(output, error));

#if !SITEMANAGEMENT
        }
#endif
        }
예제 #2
0
        public Tuple<string, string> Execute(string arguments, params object[] args)
#endif
        {

#if !SITEMANAGEMENT
            using (GetProcessStep(tracer, arguments, args))
            {
#endif
                var process = CreateProcess(arguments, args);
                process.Start();

#if !SITEMANAGEMENT
                var idleManager = new Kudu.Core.Infrastructure.IdleManager(IdleTimeout, tracer);
#else
                var idleManager = new Kudu.SiteManagement.IdleManager();
#endif
                Func<StreamReader, string> reader = (StreamReader streamReader) =>
                {
                    var strb = new StringBuilder();
                    char[] buffer = new char[1024];
                    int read;
                    while ((read = streamReader.ReadBlock(buffer, 0, buffer.Length)) != 0)
                    {
                        idleManager.UpdateActivity();
                        strb.Append(buffer, 0, read);
                    }
                    idleManager.UpdateActivity();
                    return strb.ToString();
                };

                IAsyncResult outputReader = reader.BeginInvoke(process.StandardOutput, null, null);
                IAsyncResult errorReader = reader.BeginInvoke(process.StandardError, null, null);

                process.StandardInput.Close();

                idleManager.WaitForExit(process);

                string output = reader.EndInvoke(outputReader);
                string error = reader.EndInvoke(errorReader);

#if !SITEMANAGEMENT
                tracer.TraceProcessExitCode(process);
#endif

                // Sometimes, we get an exit code of 1 even when the command succeeds (e.g. with 'git reset .').
                // So also make sure there is an error string
                if (process.ExitCode != 0)
                {
                    string text = String.IsNullOrEmpty(error) ? output : error;

                    throw new CommandLineException(Path, process.StartInfo.Arguments, text)
                    {
                        ExitCode = process.ExitCode,
                        Output = output,
                        Error = error
                    };
                }

                return Tuple.Create(output, error);

#if !SITEMANAGEMENT
            }
#endif
        }