// Run the command in the given string and restart it after
// a message was received on the buildDone channel.
355757
func runner(commandTemplate string, buildStarted <-chan string, buildSuccess <-chan bool) {
	var currentProcess *os.Process
	pipeChan := make(chan io.ReadCloser)

	go logger(pipeChan)

	go func() {
		sigChan := make(chan os.Signal, 1)
		signal.Notify(sigChan, fatalSignals...)
		<-sigChan
		log.Println(okColor("Received signal, terminating cleanly."))
		if currentProcess != nil {
			killProcess(currentProcess)
		}
		os.Exit(0)
	}()

	for {
		eventPath := <-buildStarted

		// append %0.s to use format specifier even if not supplied by user
		// to suppress warning in returned string.
		command := fmt.Sprintf("%0.s"+commandTemplate, eventPath)

		if !*flag_command_stop {
			if !<-buildSuccess {
				continue
			}
		}

		if currentProcess != nil {
			killProcess(currentProcess)
		}
		if *flag_command_stop {
			log.Println(okColor("Command stopped. Waiting for build to complete."))
			if !<-buildSuccess {
				continue
			}
		}

		log.Println(okColor("Restarting the given command."))
		cmd, stdoutPipe, stderrPipe, err := startCommand(command)

		if err != nil {
			log.Fatal(failColor("Could not start command: %s", err))
		}

		pipeChan <- stdoutPipe
		pipeChan <- stderrPipe

		currentProcess = cmd.Process
	}
}
901558
func (c *CmdSimpleFSKill) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	err = cli.SimpleFSClose(context.TODO(), c.opid)

	return err
}
1139065
func Run(argv interface{}, fn CommandFunc, descs ...string) int {
	return RunWithArgs(argv, os.Args, fn, descs...)
}
919925
func (c *DeprecatedCommand) Run(args []string) int {
	c.warn()
	return c.Command.Run(args)
}
169351
func (cmd *Command) Run(args []string) {
	cmd.Flags.SetOutput(ioutil.Discard)

	err := cmd.Flags.Parse(args)
	if err != nil {
		cmd.Usage()
		fmt.Fprintf(os.Stderr, "\nError: %v\n", err)
		os.Exit(2)
	}
	subArgs := cmd.Flags.Args()

	if len(subArgs) == 0 {
		cmd.Action(cmd, subArgs)
		return
	}

	name := subArgs[0]
	for _, subcmd := range cmd.Subcmds {
		if subcmd.Name() == name {
			subcmd.Run(subArgs[1:])
			return
		}
	}

	cmd.Action(cmd, subArgs)
}
797942
func (c *CmdSimpleFSReset) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	err = c.confirm()
	if err != nil {
		return err
	}

	err = cli.SimpleFSReset(context.TODO(), c.path)
	if err != nil {
		return err
	}

	return err
}
743928
func (c *GetKVMsCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	client := getClient(ctx)
	resp, err := client.ListKVMs(ctx, &c.req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printKVMs(c.f.tsv, resp.Kvms...)
	return 0
}
600991
func runCommand(cmd string) error {
	log.Debug("Running " + cmd)
	var c *exec.Cmd
	if runtime.GOOS == "windows" {
		c = exec.Command("cmd", "/C", cmd)
	} else {
		c = exec.Command("/bin/sh", "-c", cmd)
	}

	output, err := c.CombinedOutput()
	if err != nil {
		log.Error(fmt.Sprintf("%q", string(output)))
		return err
	}
	log.Debug(fmt.Sprintf("%q", string(output)))
	return nil
}
125267
func Run(args ...string) (string, error) {
	// TODO: use exex.CommandContext here and refactor.
	var extraArgs = []string{
		"-c", "log.showSignature=false",
	}
	args = append(extraArgs, args...)
	/* #nosec */
	var cmd = exec.Command("git", args...)
	log.WithField("args", args).Debug("running git")
	bts, err := cmd.CombinedOutput()
	log.WithField("output", string(bts)).
		Debug("git result")
	if err != nil {
		return "", errors.New(string(bts))
	}
	return string(bts), nil
}
371131
func (config *Config) Run(cmd string) (string, error) {
	if config.DisplayOutput == true {
		fmt.Printf("run: %s\n", cmd)
	}
	return config.doRun(cmd, false)
}
30484
func (c *MockSSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error {
	if c.MockRun != nil {
		return c.MockRun(command, stdout, stderr)
	}
	return ErrNotImplemented
}
941904
func (c *ReloadCommand) Run(ctx *cmd.Context) error {
	return c.RunWithAPI(ctx, func(api SpaceAPI, ctx *cmd.Context) error {
		err := api.ReloadSpaces()
		if err != nil {
			if errors.IsNotSupported(err) {
				ctx.Infof("cannot reload spaces: %v", err)
			}
			return errors.Annotate(err, "cannot reload spaces")
		}
		return nil
	})
}
1090815
func (client *sshClient) Run(cmd string) ([]byte, error) {
	// Establish a single command session
	session, err := client.client.NewSession()
	if err != nil {
		return nil, err
	}
	defer session.Close()

	// Execute the command and return any output
	client.logger.Trace("Running command on remote server", "cmd", cmd)
	return session.CombinedOutput(cmd)
}
694939
func (s *Service) RunCommand(command string, args ...string) error {
	cmd := s.commands[command]
	if cmd == nil {
		return fmt.Errorf("unknown command %q", command)
	}
	err := s.setup()
	if err != nil {
		return fmt.Errorf("error in setup: %v", err)
	}
	flagMap, args, err := parseArgs(cmd.Flags, args)
	if err != nil {
		return err
	}
	cmd.Run(&CommandContext{cmd, args, flagMap})
	return nil
}
559063
func (c *DeleteHostCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	// TODO(smut): Validate required fields client-side.
	client := getClient(ctx)
	_, err := client.DeleteHost(ctx, &c.req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	return 0
}
82798
func run(stdout, stderr io.Writer, cmd string, args ...string) error {
	c := exec.Command(cmd, args...)
	c.Stdin = os.Stdin
	c.Stdout = stdout
	c.Stderr = stderr
	return c.Run()
}
903734
func (c *TechSupportCommand) Run(args []string) int {
	c.InitOpts()
	rest, err := c.parseOpts(args)
	if err != nil {
		if errwrap.Contains(err, "flag: help requested") {
			return 0
		}
		return 1
	}
	if len(rest) != 0 {
		c.Ui.Error(c.Help())
		return 1
	}

	ri, err := sockaddr.NewRouteInfo()
	if err != nil {
		c.Ui.Error(fmt.Sprintf("error loading route information: %v", err))
		return 1
	}

	const initNumCmds = 4
	type cmdResult struct {
		cmd []string
		out string
	}
	output := make(map[string]cmdResult, initNumCmds)
	ri.VisitCommands(func(name string, cmd []string) {
		out, err := exec.Command(cmd[0], cmd[1:]...).Output()
		if err != nil {
			out = []byte(fmt.Sprintf("ERROR: command %q failed: %v", name, err))
		}

		output[name] = cmdResult{
			cmd: cmd,
			out: string(out),
		}
	})

	out := c.rowWriterOutputFactory()

	for cmdName, result := range output {
		switch c.outputMode {
		case "md":
			c.Ui.Output(fmt.Sprintf("## cmd: `%s`", cmdName))
			c.Ui.Output("")
			c.Ui.Output(fmt.Sprintf("Command: `%#v`", result.cmd))
			c.Ui.Output("```")
			c.Ui.Output(result.out)
			c.Ui.Output("```")
			c.Ui.Output("")
		case "raw":
			c.Ui.Output(fmt.Sprintf("cmd: %q: %#v", cmdName, result.cmd))
			c.Ui.Output("")
			c.Ui.Output(result.out)
			c.Ui.Output("")
		default:
			c.Ui.Error(fmt.Sprintf("Unsupported output type: %q", c.outputMode))
			return 1
		}

		out("s", "GOOS", runtime.GOOS)
		out("s", "GOARCH", runtime.GOARCH)
		out("s", "Compiler", runtime.Compiler)
		out("s", "Version", runtime.Version())
		ifs, err := net.Interfaces()
		if err != nil {
			out("v", "net.Interfaces", err)
		} else {
			for i, intf := range ifs {
				out("s", fmt.Sprintf("net.Interfaces[%d].Name", i), intf.Name)
				out("s", fmt.Sprintf("net.Interfaces[%d].Flags", i), intf.Flags)
				out("+v", fmt.Sprintf("net.Interfaces[%d].Raw", i), intf)
				addrs, err := intf.Addrs()
				if err != nil {
					out("v", fmt.Sprintf("net.Interfaces[%d].Addrs", i), err)
				} else {
					for j, addr := range addrs {
						out("s", fmt.Sprintf("net.Interfaces[%d].Addrs[%d]", i, j), addr)
					}
				}
			}
		}
	}

	return 0
}