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


Golang cmdex.RunCommandAndReturnCombinedStdoutAndStderr函数代码示例

本文整理汇总了Golang中github.com/bitrise-io/go-utils/cmdex.RunCommandAndReturnCombinedStdoutAndStderr函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCommandAndReturnCombinedStdoutAndStderr函数的具体用法?Golang RunCommandAndReturnCombinedStdoutAndStderr怎么用?Golang RunCommandAndReturnCombinedStdoutAndStderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: InstallWithAptGetIfNeeded

// InstallWithAptGetIfNeeded ...
func InstallWithAptGetIfNeeded(tool string, isCIMode bool) error {
	if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", tool); err != nil {
		if err.Error() == "exit status 1" && out == "" {
			// Tool isn't installed -- install it...
			if !isCIMode {
				log.Infof("This step requires %s, which is not installed", tool)
				allow, err := goinp.AskForBool("Would you like to install (" + tool + ") with brew ? [yes/no]")
				if err != nil {
					return err
				}
				if !allow {
					return errors.New("(" + tool + ") is required for step")
				}
			}

			log.Infof("(%s) isn't installed, installing...", tool)
			if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("sudo", "apt-get", "-y", "install", tool); err != nil {
				log.Errorf("sudo apt-get -y install %s failed -- out: (%s) err: (%s)", tool, out, err)
				return err
			}

			log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", tool)
		} else {
			// which failed
			log.Errorf("which (%s) failed -- out: (%s) err: (%s)", tool, out, err)
			return err
		}
	} else if out != "" {
		// already installed
	} else {
		log.Warnf("which (%s) -- out (%s)", tool, out)
	}

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

示例2: InstallWithAptGetIfNeeded

// InstallWithAptGetIfNeeded ...
func InstallWithAptGetIfNeeded(aptGetDep stepmanModels.AptGetDepModel, isCIMode bool) error {
	isDepInstalled := false
	// First do a "which", to see if the binary is available.
	// Can be available from another source, not just from brew,
	// e.g. it's common to use NVM or similar to install and manage the Node.js version.
	{
		if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", aptGetDep.GetBinaryName()); err != nil {
			if err.Error() == "exit status 1" && out == "" {
				isDepInstalled = false
			} else {
				// unexpected `which` error
				return fmt.Errorf("which (%s) failed -- out: (%s) err: (%s)", aptGetDep.Name, out, err)
			}
		} else if out != "" {
			isDepInstalled = true
		} else {
			// no error but which's output was empty
			return fmt.Errorf("which (%s) failed -- no error (exit code 0) but output was empty", aptGetDep.Name)
		}
	}

	// then do a package manager specific lookup
	{
		if !isDepInstalled {
			// which did not find the binary, also check in brew,
			// whether the package is installed
			isDepInstalled = checkIfAptPackageInstalled(aptGetDep.Name)
		}
	}

	if !isDepInstalled {
		// Tool isn't installed -- install it...
		if !isCIMode {
			log.Infof(`This step requires "%s" to be available, but it is not installed.`, aptGetDep.GetBinaryName())
			allow, err := goinp.AskForBoolWithDefault(`Would you like to install the "`+aptGetDep.Name+`" package with apt-get?`, true)
			if err != nil {
				return err
			}
			if !allow {
				return errors.New("(" + aptGetDep.Name + ") is required for step")
			}
		}

		log.Infof("(%s) isn't installed, installing...", aptGetDep.Name)
		if cmdOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("sudo", "apt-get", "-y", "install", aptGetDep.Name); err != nil {
			log.Errorf("sudo apt-get -y install %s failed -- out: (%s) err: (%s)", aptGetDep.Name, cmdOut, err)
			return err
		}

		log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", aptGetDep.Name)
	}

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

示例3: cmdExist

func cmdExist(cmdSlice []string) bool {
	if len(cmdSlice) == 0 {
		return false
	}

	if len(cmdSlice) == 1 {
		_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(cmdSlice[0])
		return (err == nil)
	}

	_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(cmdSlice[0], cmdSlice[1:]...)
	return (err == nil)
}
开发者ID:bitrise-io,项目名称:steps-cocoapods-install,代码行数:13,代码来源:run.go

示例4: getOsAndArch

func getOsAndArch() (string, string, error) {
	osOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-s")
	if err != nil {
		return "", "", err
	}

	archOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-m")
	if err != nil {
		return "", "", err
	}

	return osOut, archOut, nil
}
开发者ID:birmacher,项目名称:bitrise,代码行数:13,代码来源:plugins.go

示例5: InstallWithBrewIfNeeded

// InstallWithBrewIfNeeded ...
func InstallWithBrewIfNeeded(brewDep stepmanModels.BrewDepModel, isCIMode bool) error {
	isDepInstalled := false
	// First do a "which", to see if the binary is available.
	// Can be available from another source, not just from brew,
	// e.g. it's common to use NVM or similar to install and manage the Node.js version.
	if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", brewDep.GetBinaryName()); err != nil {
		if err.Error() == "exit status 1" && out == "" {
			isDepInstalled = false
		} else {
			// unexpected `which` error
			return fmt.Errorf("which (%s) failed -- out: (%s) err: (%s)", brewDep.Name, out, err)
		}
	} else if out != "" {
		isDepInstalled = true
	} else {
		// no error but which's output was empty
		return fmt.Errorf("which (%s) failed -- no error (exit code 0) but output was empty", brewDep.Name)
	}

	if !isDepInstalled {
		// which did not find the binary, also check in brew,
		// whether the package is installed
		isDepInstalled = checkIfBrewPackageInstalled(brewDep.Name)
	}

	if !isDepInstalled {
		// Tool isn't installed -- install it...
		if !isCIMode {
			log.Infof("This step requires %s, which is not installed", brewDep.Name)
			allow, err := goinp.AskForBool("Would you like to install (" + brewDep.Name + ") with brew?")
			if err != nil {
				return err
			}
			if !allow {
				return errors.New("(" + brewDep.Name + ") is required for step")
			}
		}

		log.Infof("(%s) isn't installed, installing...", brewDep.Name)
		if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("brew", "install", brewDep.Name); err != nil {
			log.Errorf("brew install %s failed -- out: (%s) err: (%s)", brewDep.Name, out, err)
			return err
		}
		log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", brewDep.Name)
	}

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

示例6: Test_InvalidCommand

func Test_InvalidCommand(t *testing.T) {
	t.Log("Invalid command")
	{
		_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "invalidcmd")
		require.EqualError(t, err, "exit status 1")
	}
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:7,代码来源:invalid_command_test.go

示例7: systemOsName

func systemOsName() (string, error) {
	osOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-s")
	if err != nil {
		return "", err
	}
	return strip(osOut), nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:7,代码来源:models_methods.go

示例8: StepmanPrintRawStepList

// StepmanPrintRawStepList ...
func StepmanPrintRawStepList(collection string) error {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-list", "--collection", collection, "--format", "raw"}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return err
	}

	fmt.Println(out)
	return nil
}
开发者ID:andrewhavens,项目名称:bitrise,代码行数:12,代码来源:run.go

示例9: Run

// Run ...
func (command PrintableCommand) Run() (string, error) {
	log.Debugf("=> (%#v)", command)

	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(command.Name, command.Args...)
	if err != nil {
		log.Fatalf("Failed to execute:\ncommand:(%s),\noutput:(%s),\nerror:(%#v)", command.RawCommand, out, err)
	}
	log.Debugf("output:\n(%s)", out)

	return out, err
}
开发者ID:bitrise-tools,项目名称:releaseman,代码行数:12,代码来源:command.go

示例10: StepmanPrintRawLocalStepInfo

// StepmanPrintRawLocalStepInfo ...
func StepmanPrintRawLocalStepInfo(pth string) error {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-info", "--step-yml", pth, "--format", "raw"}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return err
	}

	fmt.Println(out)
	return nil
}
开发者ID:andrewhavens,项目名称:bitrise,代码行数:12,代码来源:run.go

示例11: Test_VersionOutput

func Test_VersionOutput(t *testing.T) {
	t.Log("Version")
	{
		out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "version")
		require.NoError(t, err)
		require.Equal(t, "1.5.0", out)
	}

	t.Log("Version --full")
	{
		out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "version", "--full")
		require.NoError(t, err)

		expectedOSVersion := fmt.Sprintf("%s (%s)", runtime.GOOS, runtime.GOARCH)
		expectedVersionOut := fmt.Sprintf(`version: 1.5.0
format version: 1.4.0
os: %s
go: %s
build number: 
commit:`, expectedOSVersion, runtime.Version())

		require.Equal(t, expectedVersionOut, out)
	}
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:24,代码来源:version_test.go

示例12: RunXcodebuildCommand

// RunXcodebuildCommand ...
func (xccmd CommandModel) RunXcodebuildCommand(xcodebuildActionArgs ...string) (string, error) {
	xcodeCmdParamsToRun, err := xccmd.transformToXcodebuildParams(xcodebuildActionArgs...)
	if err != nil {
		return "", err
	}

	log.Infof("$ xcodebuild %s", cmdex.PrintableCommandArgs(true, xcodeCmdParamsToRun))
	fmt.Print("Running and analyzing log ...")
	xcoutput, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("xcodebuild", xcodeCmdParamsToRun...)
	if err != nil {
		return xcoutput, fmt.Errorf("Failed to run xcodebuild command, error: %s", err)
	}

	log.Debugf("xcoutput: %s", xcoutput)
	return xcoutput, nil
}
开发者ID:bitrise-tools,项目名称:codesigndoc,代码行数:17,代码来源:xcodecmd.go

示例13: StepmanStepInfo

// StepmanStepInfo ...
func StepmanStepInfo(collection, stepID, stepVersion string) (models.StepInfoModel, error) {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-info", "--collection", collection,
		"--id", stepID, "--version", stepVersion}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return models.StepInfoModel{}, fmt.Errorf("Failed to run stepman step-info, err: %s", err)
	}

	stepInfo := models.StepInfoModel{}
	if err := json.Unmarshal([]byte(out), &stepInfo); err != nil {
		return models.StepInfoModel{}, err
	}

	return stepInfo, nil
}
开发者ID:bazscsa,项目名称:bitrise-cli,代码行数:17,代码来源:run.go

示例14: EnvmanVersion

// EnvmanVersion ...
func EnvmanVersion() (version.Version, error) {
	logLevel := log.GetLevel().String()
	args := []string{"--loglevel", logLevel, "--version"}
	versionOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("envman", args...)
	if err != nil {
		return version.Version{}, err
	}

	versionPtr, err := version.NewVersion(versionOut)
	if err != nil {
		return version.Version{}, err
	}
	if versionPtr == nil {
		return version.Version{}, fmt.Errorf("Failed to parse version (%s)", versionOut)
	}

	return *versionPtr, nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:19,代码来源:tool_version.go

示例15: NewRubyCommandModel

// NewRubyCommandModel ...
func NewRubyCommandModel() (RubyCommandModel, error) {
	whichRuby, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", "ruby")
	if err != nil {
		return RubyCommandModel{}, err
	}

	command := RubyCommandModel{}

	if whichRuby == systemRubyPth {
		command.rubyInstallType = SystemRuby
	} else if whichRuby == brewRubyPth {
		command.rubyInstallType = BrewRuby
	} else if cmdExist([]string{"rvm", "-v"}) {
		command.rubyInstallType = RVMRuby
	} else if cmdExist([]string{"rbenv", "-v"}) {
		command.rubyInstallType = RbenvRuby
	} else {
		return RubyCommandModel{}, errors.New("unkown ruby installation type")
	}

	return command, nil
}
开发者ID:bitrise-io,项目名称:steps-cocoapods-install,代码行数:23,代码来源:run.go


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