Exemplo n.º 1
0
 public ExecCmdResult Run(ushort numTries = 1, TimeSpan? retrySleepInterval = null, bool expectError = false)
 {
     bool success = false;
     string output = null, errout = null;
     try
     {
         for (ushort i = 0; i < numTries && false == success; ++i)
         {
             log.Debug(Resources.ExecCmd_Cmd_Fmt, cmd, arguments);
             var p = new RedirectedProcess(cmd, arguments);
             p.StartAndWait();
             output = p.STDOUT;
             errout = p.STDERR;
             success = 0 == p.ExitCode;
             if (false == success)
             {
                 if (false == expectError)
                 {
                     log.Error(Resources.ExecCmd_CmdFailed_Fmt, cmd, arguments, errout);
                 }
                 if (numTries > 1 && retrySleepInterval.HasValue)
                 {
                     Thread.Sleep(retrySleepInterval.Value);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         success = false;
         output = null;
         log.Error(ex);
     }
     return new ExecCmdResult(success, output);
 }
Exemplo n.º 2
0
        public ExecCmdResult Run(ushort numTries = 1, TimeSpan?retrySleepInterval = null, bool expectError = false)
        {
            bool   success = false;
            string output = null, errout = null;

            try
            {
                for (ushort i = 0; i < numTries && false == success; ++i)
                {
                    log.Debug(Resources.ExecCmd_Cmd_Fmt, cmd, arguments);
                    var p = new RedirectedProcess(cmd, arguments);
                    p.StartAndWait();
                    output  = p.STDOUT;
                    errout  = p.STDERR;
                    success = 0 == p.ExitCode;
                    if (false == success)
                    {
                        if (false == expectError)
                        {
                            log.Error(Resources.ExecCmd_CmdFailed_Fmt, cmd, arguments, errout);
                        }
                        if (numTries > 1 && retrySleepInterval.HasValue)
                        {
                            Thread.Sleep(retrySleepInterval.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                output  = null;
                log.Error(ex);
            }
            return(new ExecCmdResult(success, output));
        }