当前位置: 首页>>代码示例>>Golang>>正文


Golang Cmd.CombinedOutput方法代码示例

本文整理汇总了Golang中os/exec.Cmd.CombinedOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang Cmd.CombinedOutput方法的具体用法?Golang Cmd.CombinedOutput怎么用?Golang Cmd.CombinedOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os/exec.Cmd的用法示例。


在下文中一共展示了Cmd.CombinedOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: builder

// Call in its own goroutine to rebuild docs when buildChan is sent events
func builder(path string, cmd []string, buildChan chan bool) {
	for {
		// Block waiting for a new event
		<-buildChan

		// Pause briefly as editors often emit multiple events at once
		time.Sleep(100 * time.Millisecond)

		// Now just throw away the newest build change event
		select {
		case <-buildChan:
		default:
		}

		// And finally actually build the thing
		var c *exec.Cmd
		if len(cmd) == 1 {
			c = exec.Command(cmd[0])
		} else {
			c = exec.Command(cmd[0], cmd[1:]...)
		}
		out, err := c.CombinedOutput()
		if err != nil {
			log.Fatalf("Error running `%v`: %v\n", cmd, err)
		}
		log.Printf("%v\n%s", cmd, out)
	}
}
开发者ID:schmichael,项目名称:gosphinxbuild,代码行数:29,代码来源:gosphinxbuild.go

示例2: authorized

func authorized() bool {
	if authorizedCheck() {
		return true
	}

	logger.Debug("Requesting superuser authentication")

	var cmd *exec.Cmd
	var sudoTool = "sudo"
	/*if !authorizedIsCheck() {
		_, err := exec.LookPath("gksudo")
		if err == nil {
			return "gksudo"
		}
	}*/
	if sudoTool == "sudo" {
		cmd = exec.Command("sudo", "echo")
	} else {
		cmd = exec.Command("gksudo", "darknet")
	}
	_, err := cmd.CombinedOutput()
	if err != nil {
		return false
	}

	if authorizedCheck() {
		return true
	}

	return false
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:31,代码来源:linux.go

示例3: runCommandWithOutput

func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
	exitCode = 0
	out, err := cmd.CombinedOutput()
	exitCode = processExitCode(err)
	output = string(out)
	return
}
开发者ID:baoruxing,项目名称:docker,代码行数:7,代码来源:utils.go

示例4: execute

func execute(cmd *exec.Cmd) (string, error) {
	output, err := cmd.CombinedOutput()
	if err != nil {
		switch err.(type) {
		case *exec.ExitError:
			if len(output) > 0 {
				return string(output), fmt.Errorf(
					"executing %s failed: %s, output: %s",
					strings.Join(cmd.Args, " "), err, output,
				)
			}

			return string(output), fmt.Errorf(
				"executing %s failed: %s, output is empty",
				strings.Join(cmd.Args, " "), err,
			)
		default:
			return string(output), fmt.Errorf(
				"executing %s failed: %s",
				strings.Join(cmd.Args, " "), err,
			)
		}
	}

	return string(output), nil
}
开发者ID:kovetskiy,项目名称:linterd,代码行数:26,代码来源:utils.go

示例5: execute_python

func execute_python(pyStr string) ([]byte, error) {
	//Write python program to a file
	file, _ := os.Create("test.py")
	io.WriteString(file, pyStr)

	var out []byte
	var err error

	timeout := make(chan bool, 1)
	go func() {
		time.Sleep(3e9)
		timeout <- true
	}()

	ch := make(chan bool, 1)
	var cmd *exec.Cmd
	go func() {
		//Execute the program
		cmd = exec.Command("python", "test.py")
		out, err = cmd.CombinedOutput()
		ch <- true
	}()

	select {
	case <-ch:
		// Command finished in time.
		return out, err
	case <-timeout:
		// Stop forever loop command.
		cmd.Process.Kill()
		return []byte("人家被你玩坏了啦"), errors.New("人家被你玩坏了啦")
	}
}
开发者ID:ufo22940268,项目名称:two-server-others,代码行数:33,代码来源:fmt.go

示例6: DependencyTryCheckTool

// DependencyTryCheckTool ...
func DependencyTryCheckTool(tool string) error {
	var cmd *exec.Cmd
	errMsg := ""

	switch tool {
	case "xcode":
		cmd = exec.Command("xcodebuild", "-version")
		errMsg = "The full Xcode app is not installed, required for this step. You can install it from the App Store."
		break
	default:
		cmdFields := strings.Fields(tool)
		if len(cmdFields) >= 2 {
			cmd = exec.Command(cmdFields[0], cmdFields[1:]...)
		} else if len(cmdFields) == 1 {
			cmd = exec.Command(cmdFields[0])
		} else {
			return fmt.Errorf("Invalid tool name (%s)", tool)
		}
	}

	outBytes, err := cmd.CombinedOutput()
	if err != nil {
		if errMsg != "" {
			return errors.New(errMsg)
		}
		log.Infof("Output was: %s", outBytes)
		return fmt.Errorf("Dependency check failed for: %s", tool)
	}

	return nil
}
开发者ID:godrei,项目名称:bitrise,代码行数:32,代码来源:dependencies.go

示例7: Run

func (c Command) Run(s HookState) error {
	b, err := json.Marshal(s)
	if err != nil {
		return err
	}
	cmd := exec.Cmd{
		Path:  c.Path,
		Args:  c.Args,
		Env:   c.Env,
		Stdin: bytes.NewReader(b),
	}
	errC := make(chan error, 1)
	go func() {
		out, err := cmd.CombinedOutput()
		if err != nil {
			err = fmt.Errorf("%s: %s", err, out)
		}
		errC <- err
	}()
	if c.Timeout != nil {
		select {
		case err := <-errC:
			return err
		case <-time.After(*c.Timeout):
			cmd.Process.Kill()
			cmd.Wait()
			return fmt.Errorf("hook ran past specified timeout of %.1fs", c.Timeout.Seconds())
		}
	}
	return <-errC
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:31,代码来源:config.go

示例8: cleanup

func cleanup(directory string) {
	temp, err := ioutil.TempDir("", "")
	isError(err, "")
	files, err := ioutil.ReadDir(directory)
	isError(err, "")
	if 1 == len(files) {
		folder := filepath.Join(directory, files[0].Name())
		// Move to a tmp directory
		files, err = ioutil.ReadDir(folder)
		isError(err, "")
		for _, file := range files {
			var cmd *exec.Cmd
			cmd = exec.Command("mv", file.Name(), temp)
			cmd.Dir = folder
			output, err := cmd.CombinedOutput()
			isError(err, string(output))
		}
		err = os.RemoveAll(folder)
		isError(err, "")
		// move to the directory
		files, err = ioutil.ReadDir(temp)
		isError(err, "")
		for _, file := range files {
			var cmd *exec.Cmd
			cmd = exec.Command("mv", file.Name(), directory)
			cmd.Dir = temp
			output, err := cmd.CombinedOutput()
			isError(err, string(output))
		}
	}
}
开发者ID:matteosuppo,项目名称:arduino-install-cores,代码行数:31,代码来源:main.go

示例9: check_ibgp

func check_ibgp(version int) {
	var cmd *exec.Cmd
	if version == 4 {
		cmd = exec.Command(BIRDC, "show protocols")
	} else if version == 6 {
		cmd = exec.Command(BIRDC6, "show protocols")
	} else {
		return
	}
	output, err := cmd.CombinedOutput()
	check(err)

	lines := strings.Split(string(output), "\n")
	for i := 0; i < len(lines); i++ {
		if i < 2 {
			continue
		}

		matched, err := regexp.MatchString("^bb_[ab]", lines[i])
		check(err)
		if !matched {
			continue
		}

		columns := regexp.MustCompile(" +").Split(string(lines[i]), -1)
		if columns[BIRD_PROTOCOL_STATUS_COLUMN] != "Established" {
			fmt.Printf("IPv%d IBGP session %s is in status %s\n", version,
				columns[BIRD_PROTOCOL_NAME_COLUMN],
				columns[BIRD_PROTOCOL_STATUS_COLUMN])
		}
	}
}
开发者ID:boiert,项目名称:AS201701-ops,代码行数:32,代码来源:smasher.go

示例10: run

func run(cmd *exec.Cmd) (string, error) {
	data, err := cmd.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("%s", data)
	}
	return string(data), err
}
开发者ID:postfix,项目名称:git,代码行数:7,代码来源:git_test.go

示例11: Run

func (c cmdAction) Run() StepOp {
	start := time.Now()

	var cmd *exec.Cmd
	command := evaluate(c.command, c.event)
	args := strings.Fields(command)
	if len(args) > 1 {
		cmd = exec.Command(args[0], args[1:]...)
	} else {
		cmd = exec.Command(args[0])
	}

	out, err := cmd.CombinedOutput()
	elapsed := time.Now().Sub(start)
	if err != nil {
		log.WithFields(log.Fields{
			"error":   err,
			"elapsed": elapsed,
		}).Error(highlight(fmt.Sprintf("Run: %s", command), "red+b"))
	} else {
		log.WithFields(log.Fields{
			"elapsed": time.Now().Sub(start),
		}).Info(highlight(fmt.Sprintf("Run: %s", command), "cyan+b"))
	}
	if len(out) > 0 {
		fmt.Print(string(out))
	}

	if err != nil {
		return Halt
	}
	return Continue
}
开发者ID:parkghost,项目名称:watchf,代码行数:33,代码来源:runner.go

示例12: Md5sumCheck

func Md5sumCheck(runUser, workdir, tarfile, md5file string) error {
	var cmd *exec.Cmd
	var md5Actual string
	if "darwin" == runtime.GOOS {
		cmd = BuildCommand(runUser, "md5", "-q", path.Join(workdir, tarfile))
	} else {
		cmd = BuildCommand(runUser, "md5sum", path.Join(workdir, tarfile))
	}
	cmd.Dir = file.SelfDir()
	bs, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("cd %s; md5sum -c %s fail", workdir, md5file)
	}
	strMd5file, _ := file.ToString(path.Join(workdir, md5file))
	if "" == strMd5file {
		return fmt.Errorf("md5file is empty")
	}

	if "darwin" == runtime.GOOS {
		md5Actual = strings.Replace(string(bs), "\n", "", -1)
	} else {
		md5Actual = strings.Fields(string(bs))[0]
	}

	md5Except := strings.Fields(strMd5file)[0]

	if md5Actual == md5Except {
		return nil
	}
	return fmt.Errorf("md5Actual:%s, md5Except:%s<<<===end", md5Actual, md5Except)
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:31,代码来源:start.go

示例13: RunCmd

func RunCmd(command string) (output string, exitCode int, startedAt time.Time, finishedAt time.Time) {

	var cmd *exec.Cmd

	if runtime.GOOS == "windows" {
		log.Infof("Command: %s", command)
		cmd = exec.Command("cmd", "/C", command)
	} else {
		log.Infof("Command: %s %s", "/bin/sh -c", command)
		cmd = exec.Command("/bin/sh", "-c", command)
	}

	startedAt = time.Now()
	bytes, err := cmd.CombinedOutput()
	finishedAt = time.Now()
	output = strings.TrimSpace(string(bytes))
	exitCode = extractExitCode(err)

	log.Debugf("Starting Time: %s", startedAt.Format(TimeStampLayout))
	log.Debugf("End Time: %s", finishedAt.Format(TimeStampLayout))
	log.Debugf("Output")
	log.Debugf("")
	log.Debugf("%s", output)
	log.Debugf("")
	log.Infof("Exit Code: %d", exitCode)
	return
}
开发者ID:odacremolbap,项目名称:concerto,代码行数:27,代码来源:exec.go

示例14: execCommand

func execCommand(_result map[string]int, _cmd []string) {
	var r ResultSlice

	for k, v := range _result {
		r.Results = append(r.Results, Result{Host: k, Count: v})
	}

	b, err := json.Marshal(r)
	HandleError(err)

	var cmd *exec.Cmd
	if len(_cmd) == 0 {
		cmd = exec.Command(_cmd[0])
	} else {
		cmd = exec.Command(_cmd[0], _cmd[1:]...)
	}

	stdin, err := cmd.StdinPipe()
	HandleError(err)

	io.WriteString(stdin, string(b))

	stdin.Close()

	out, err := cmd.CombinedOutput()
	HandleError(err)

	fmt.Println(string(out))
}
开发者ID:ariarijp,项目名称:canaryeye,代码行数:29,代码来源:canaryeye.go

示例15: execCmd

func (me *App) execCmd(cmd *exec.Cmd) (string, error) {
	out, err := cmd.CombinedOutput()

	args := strings.Join(cmd.Args, " ")

	output := strings.Trim(string(out), "\n ")

	if output != "" {
		output = fmt.Sprintf("\n\n%s", output)
	}

	str := fmt.Sprintf(
		"$ %v%s\n\n",
		args,
		output,
	)

	fmt.Print(str)
	log.Print(str)

	if err != nil {
		log.Printf("Command %s returned error: %s", args, err)
	}

	return string(out), err
}
开发者ID:norabirkin,项目名称:vimscripts,代码行数:26,代码来源:app.go


注:本文中的os/exec.Cmd.CombinedOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。