func (r *RunParams) Run() error {
	if runtime.GOOS == "windows" {
		r.Environment = mergeEnvironment(r.Environment)
	}

	tempDir, err := ioutil.TempDir("", "juju-exec")
	if err != nil {
		return err
	}

	shell, args, err := shellAndArgs(tempDir, r.Commands, r.User)
	if err != nil {
		if err := os.RemoveAll(tempDir); err != nil {
			logger.Warningf("failed to remove temporary directory: %v", err)
		}
		return err
	}

	r.ps = exec.Command(shell, args...)
	if r.Environment != nil {
		r.ps.Env = r.Environment
	}
	if r.WorkingDir != "" {
		r.ps.Dir = r.WorkingDir
	}

	r.populateSysProcAttr()

	// If there is no user provided KillProcess function we
	// use the default one.
	if r.KillProcess == nil {
		r.KillProcess = KillProcess
	}

	r.tempDir = tempDir
	r.stdout = &bytes.Buffer{}
	r.stderr = &bytes.Buffer{}

	r.ps.Stdout = r.stdout
	r.ps.Stderr = r.stderr

	return r.ps.Start()
}
// Run sets up the command environment (environment variables, working dir)
// and starts the process. The commands are passed into bash on Linux machines
// and to powershell on Windows machines.
Run sets up the command environment (environment variables, working dir)
and starts the process. The commands are passed into bash on Linux machines
and to powershell on Windows machines.
// Run sets up the command environment ( environment variables working dir ) // and starts the process . The commands are passed into bash on Linux machines // and to powershell on Windows machines .
func (r *RunParams) Run() error {
	if runtime.GOOS == "windows" {
		r.Environment = mergeEnvironment(r.Environment)
	}
	tempDir, err := ioutil.TempDir("", "juju-exec")
	if err != nil {
		return err
	}
	shell, args, err := shellAndArgs(tempDir, r.Commands, r.User)
	if err != nil {
		if err := os.RemoveAll(tempDir); err != nil {
			logger.Warningf("failed to remove temporary directory: %v", err)
		}
		return err
	}
	r.ps = exec.Command(shell, args...)
	if r.Environment != nil {
		r.ps.Env = r.Environment
	}
	if r.WorkingDir != "" {
		r.ps.Dir = r.WorkingDir
	}
	r.populateSysProcAttr()
	if r.KillProcess == nil {
		r.KillProcess = KillProcess
	}
	r.tempDir = tempDir
	r.stdout = &bytes.Buffer{}
	r.stderr = &bytes.Buffer{}
	r.ps.Stdout = r.stdout
	r.ps.Stderr = r.stderr
	return r.ps.Start()
}
func ( r * RunParams ) Run ( ) error { if runtime . GOOS == " " { r . Environment = mergeEnvironment ( r . Environment ) } tempDir , err := ioutil . TempDir ( " " , " " ) if err != nil { return err } shell , args , err := shellAndArgs ( tempDir , r . Commands , r . User ) if err != nil { if err := os . RemoveAll ( tempDir ) ; err != nil { logger . Warningf ( " " , err ) } return err } r . ps = exec . Command ( shell , args ... ) if r . Environment != nil { r . ps . Env = r . Environment } if r . WorkingDir != " " { r . ps . Dir = r . WorkingDir } r . populateSysProcAttr ( ) if r . KillProcess == nil { r . KillProcess = KillProcess } r . tempDir = tempDir r . stdout = & bytes . Buffer { } r . stderr = & bytes . Buffer { } r . ps . Stdout = r . stdout r . ps . Stderr = r . stderr return r . ps . Start ( ) }
Run sets up the command environment (environment variables, working dir)
and starts the process.
Run sets up the command environment ( environment variables working dir ) and starts the process .
// If there is no user provided KillProcess function we // use the default one.