// Run runs the command, and returns the result as an error. func (c *Cmd) Run() error { if err := c.Start(); err != nil { return err } err := c.Wait() if exitError, ok := err.(*exec.ExitError); ok && exitError != nil { status := exitError.ProcessState.Sys().(syscall.WaitStatus) if status.Exited() { return cmd.NewRcPassthroughError(status.ExitStatus()) } } return err }
func (c *RunCommand) Run(ctx *cmd.Context) error { client, err := getAPIClient(c.EnvName) if err != nil { return err } defer client.Close() var runResults []params.RunResult if c.all { runResults, err = client.RunOnAllMachines(c.commands, c.timeout) } else { params := params.RunParams{ Commands: c.commands, Timeout: c.timeout, Machines: c.machines, Services: c.services, Units: c.units, } runResults, err = client.Run(params) } if err != nil { return err } // If we are just dealing with one result, AND we are using the smart // format, then pretend we were running it locally. if len(runResults) == 1 && c.out.Name() == "smart" { result := runResults[0] ctx.Stdout.Write(result.Stdout) ctx.Stderr.Write(result.Stderr) if result.Error != "" { // Convert the error string back into an error object. return fmt.Errorf("%s", result.Error) } if result.Code != 0 { return cmd.NewRcPassthroughError(result.Code) } return nil } c.out.Write(ctx, ConvertRunResults(runResults)) return nil }
func (c *RunCommand) Run(ctx *cmd.Context) error { if c.showHelp { return gnuflag.ErrHelp } var result *exec.ExecResponse var err error if c.noContext { result, err = c.executeNoContext() } else { result, err = c.executeInUnitContext() } if err != nil { return err } ctx.Stdout.Write(result.Stdout) ctx.Stderr.Write(result.Stderr) return cmd.NewRcPassthroughError(result.Code) }