func RunControlOut(cmdArgs []string, user string, exitOnFailure bool, out *bytes.Buffer, in *bytes.Buffer) error {
	if CommandDebug {
		fmt.Println(cmdArgs, user, exitOnFailure)
	}
	cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
	cmd.Env = os.Environ()
	if len(user) != 0 {
		cmd.SysProcAttr = &syscall.SysProcAttr{}
		uids, _ := RunControl([]string{"id", "-u", user}, "", true, "")
		uid, _ := strconv.Atoi(strings.TrimSpace(uids))
		gids, _ := RunControl([]string{"id", "-g", user}, "", true, "")
		gid, _ := strconv.Atoi(strings.TrimSpace(gids))
		cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
	}

	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	if out != nil {
		cmd.Stdout = out
		//cmd.Stderr = out // comment to not capture stderr
	}
	if in != nil {
		cmd.Stdin = in
	}

	if err := cmd.Run(); err != nil {
		if exitOnFailure {
			fmt.Fprintln(os.Stderr, strings.Join(cmdArgs, " ")+": "+fmt.Sprint(err)+": "+out.String())
			os.Exit(1)
		} else {
			return fmt.Errorf(strings.Join(cmdArgs, " ") + ": " + fmt.Sprint(err) + ": " + out.String() + "\n")
		}
	}
	return nil
}
// RunControlOut takes a command and runs it, control is for whether to exit, allows output to go to stdout
RunControlOut takes a command and runs it, control is for whether to exit, allows output to go to stdout
// RunControlOut takes a command and runs it control is for whether to exit allows output to go to stdout
func RunControlOut(cmdArgs []string, user string, exitOnFailure bool, out *bytes.Buffer, in *bytes.Buffer) error {
	if CommandDebug {
		fmt.Println(cmdArgs, user, exitOnFailure)
	}
	cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
	cmd.Env = os.Environ()
	if len(user) != 0 {
		cmd.SysProcAttr = &syscall.SysProcAttr{}
		uids, _ := RunControl([]string{"id", "-u", user}, "", true, "")
		uid, _ := strconv.Atoi(strings.TrimSpace(uids))
		gids, _ := RunControl([]string{"id", "-g", user}, "", true, "")
		gid, _ := strconv.Atoi(strings.TrimSpace(gids))
		cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
	}
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if out != nil {
		cmd.Stdout = out
	}
	if in != nil {
		cmd.Stdin = in
	}
	if err := cmd.Run(); err != nil {
		if exitOnFailure {
			fmt.Fprintln(os.Stderr, strings.Join(cmdArgs, " ")+": "+fmt.Sprint(err)+": "+out.String())
			os.Exit(1)
		} else {
			return fmt.Errorf(strings.Join(cmdArgs, " ") + ": " + fmt.Sprint(err) + ": " + out.String() + "\n")
		}
	}
	return nil
}
func RunControlOut ( cmdArgs [ ] string , user string , exitOnFailure bool , out * bytes . Buffer , in * bytes . Buffer ) error { if CommandDebug { fmt . Println ( cmdArgs , user , exitOnFailure ) } cmd := exec . Command ( cmdArgs [ 0 ] , cmdArgs [ 1 : ] ... ) cmd . Env = os . Environ ( ) if len ( user ) != 0 { cmd . SysProcAttr = & syscall . SysProcAttr { } uids , _ := RunControl ( [ ] string { " " , " " , user } , " " , true , " " ) uid , _ := strconv . Atoi ( strings . TrimSpace ( uids ) ) gids , _ := RunControl ( [ ] string { " " , " " , user } , " " , true , " " ) gid , _ := strconv . Atoi ( strings . TrimSpace ( gids ) ) cmd . SysProcAttr . Credential = & syscall . Credential { Uid : uint32 ( uid ) , Gid : uint32 ( gid ) } } cmd . Stdin = os . Stdin cmd . Stdout = os . Stdout cmd . Stderr = os . Stderr if out != nil { cmd . Stdout = out } if in != nil { cmd . Stdin = in } if err := cmd . Run ( ) ; err != nil { if exitOnFailure { fmt . Fprintln ( os . Stderr , strings . Join ( cmdArgs , " " ) + " " + fmt . Sprint ( err ) + " " + out . String ( ) ) os . Exit ( 1 ) } else { return fmt . Errorf ( strings . Join ( cmdArgs , " " ) + " " + fmt . Sprint ( err ) + " " + out . String ( ) + " \n " ) } } return nil }
RunControlOut takes a command and runs it, control is for whether to exit, allows output to go to stdout
RunControlOut takes a command and runs it control is for whether to exit allows output to go to stdout
//cmd.Stderr = out // comment to not capture stderr