func (s *commandSuite) TestRunCommandCombinesOutput(c *gc.C) { content := `#!/bin/bash --norc echo stdout echo stderr 1>&2 ` patchExecutable(s, c.MkDir(), "test-output", content) output, err := utils.RunCommand("test-output") c.Assert(err, gc.IsNil) c.Assert(output, gc.Equals, "stdout\nstderr\n") }
func (s *commandSuite) TestRunCommandNonZeroExit(c *gc.C) { content := `#!/bin/bash --norc echo stdout exit 42 ` patchExecutable(s, c.MkDir(), "test-output", content) output, err := utils.RunCommand("test-output") c.Assert(err, gc.ErrorMatches, `exit status 42`) c.Assert(output, gc.Equals, "stdout\n") }
// run the command and return the combined output. func run(command string, args ...string) (output string, err error) { logger.Tracef("%s %v", command, args) output, err = utils.RunCommand(command, args...) logger.Tracef("output: %v", output) return output, err }
func runSSHImportId(keyId string) (string, error) { return utils.RunCommand("ssh-import-id", "-o", "-", keyId) }