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


Golang RunParams.Wait方法代码示例

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


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

示例1: RunCommands

// RunCommands exists to satisfy the Runner interface.
func (runner *runner) RunCommands(commands string) (*utilexec.ExecResponse, error) {
	srv, err := runner.startJujucServer()
	if err != nil {
		return nil, err
	}
	defer srv.Close()

	env, err := runner.context.HookVars(runner.paths)
	if err != nil {
		return nil, errors.Trace(err)
	}
	command := utilexec.RunParams{
		Commands:    commands,
		WorkingDir:  runner.paths.GetCharmDir(),
		Environment: env,
	}

	err = command.Run()
	if err != nil {
		return nil, err
	}
	runner.context.SetProcess(command.Process())

	// Block and wait for process to finish
	result, err := command.Wait()
	return result, runner.context.Flush("run commands", err)
}
开发者ID:snailwalker,项目名称:juju,代码行数:28,代码来源:runner.go

示例2: runScript

// runScript executes the given lines in bash
func (c *Client) runScript(lines ...string) error {
	p := exec.RunParams{
		Commands: strings.Join(lines, "\n"),
	}

	os.MkdirAll(c.SccDir, 0755)
	p.WorkingDir = c.SccDir
	if err := p.Run(); err != nil {
		return err
	}

	if r, err := p.Wait(); err != nil {
		return err
	} else {
		os.Stderr.Write(r.Stderr)
		os.Stdout.Write(r.Stdout)
		if r.Code != 0 {
			return errors.New("Script failed")
		}

		return nil
	}
}
开发者ID:mever,项目名称:steam,代码行数:24,代码来源:client.go

示例3: TestRunCommands

func (*execSuite) TestRunCommands(c *gc.C) {
	newDir, err := longPathAsString(c.MkDir())
	c.Assert(err, gc.IsNil)
	for i, test := range []struct {
		message     string
		commands    string
		workingDir  string
		environment []string
		stdout      string
		stderr      string
		code        int
	}{
		{
			message:  "test stdout capture",
			commands: "echo 'testing stdout'",
			stdout:   "testing stdout\r\n",
		}, {
			message:  "test stderr capture",
			commands: "Write-Error 'testing stderr'",
			stderr:   "testing stderr\r\n",
		}, {
			message:  "test return code",
			commands: "exit 42",
			code:     42,
		}, {
			message:    "test working dir",
			commands:   "(pwd).Path",
			workingDir: newDir,
			stdout:     filepath.FromSlash(newDir) + "\r\n",
		}, {
			message:     "test environment",
			commands:    "echo $env:OMG_IT_WORKS",
			environment: []string{"OMG_IT_WORKS=like magic"},
			stdout:      "like magic\r\n",
		},
	} {
		c.Logf("%v: %s", i, test.message)

		params := exec.RunParams{
			Commands:    test.commands,
			WorkingDir:  test.workingDir,
			Environment: test.environment,
		}

		result, err := exec.RunCommands(params)
		c.Assert(err, gc.IsNil)
		c.Assert(string(result.Stdout), gc.Equals, test.stdout)
		c.Assert(string(result.Stderr), jc.Contains, test.stderr)
		c.Assert(result.Code, gc.Equals, test.code)

		err = params.Run()
		c.Assert(err, gc.IsNil)
		c.Assert(params.Process(), gc.Not(gc.IsNil))
		result, err = params.Wait()
		c.Assert(err, gc.IsNil)
		c.Assert(string(result.Stdout), gc.Equals, test.stdout)
		c.Assert(string(result.Stderr), jc.Contains, test.stderr)
		c.Assert(result.Code, gc.Equals, test.code)

	}
}
开发者ID:rogpeppe,项目名称:juju-utils,代码行数:61,代码来源:exec_windows_test.go

示例4: TestRunCommands

func (*execSuite) TestRunCommands(c *gc.C) {
	newDir := c.MkDir()

	for i, test := range []struct {
		message     string
		commands    string
		workingDir  string
		environment []string
		stdout      string
		stderr      string
		code        int
	}{
		{
			message:  "test stdout capture",
			commands: "echo testing stdout",
			stdout:   "testing stdout\n",
		}, {
			message:  "test stderr capture",
			commands: "echo testing stderr >&2",
			stderr:   "testing stderr\n",
		}, {
			message:  "test return code",
			commands: "exit 42",
			code:     42,
		}, {
			message:    "test working dir",
			commands:   "pwd",
			workingDir: newDir,
			stdout:     newDir + "\n",
		}, {
			message:     "test environment",
			commands:    "echo $OMG_IT_WORKS",
			environment: []string{"OMG_IT_WORKS=like magic"},
			stdout:      "like magic\n",
		}, {
			message:  "multiple commands",
			commands: "cat\necho 123",
			stdout:   "123\n",
		},
	} {
		c.Logf("%v: %s", i, test.message)

		params := exec.RunParams{
			Commands:    test.commands,
			WorkingDir:  test.workingDir,
			Environment: test.environment,
		}

		result, err := exec.RunCommands(params)
		c.Assert(err, gc.IsNil)
		c.Assert(string(result.Stdout), gc.Equals, test.stdout)
		c.Assert(string(result.Stderr), gc.Equals, test.stderr)
		c.Assert(result.Code, gc.Equals, test.code)

		err = params.Run()
		c.Assert(err, gc.IsNil)
		c.Assert(params.Process(), gc.Not(gc.IsNil))
		result, err = params.Wait()
		c.Assert(err, gc.IsNil)
		c.Assert(string(result.Stdout), gc.Equals, test.stdout)
		c.Assert(string(result.Stderr), gc.Equals, test.stderr)
		c.Assert(result.Code, gc.Equals, test.code)

	}
}
开发者ID:rogpeppe,项目名称:juju-utils,代码行数:65,代码来源:exec_linux_test.go


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