I am trying to execute following shell command with Go.
{ echo $password; echo $password; } | kadmin.local -q 'cpw user'
Below changePassword
is not allowing me to pipe in both password to kadmin.local
utility. I have another utility where I need to pass only one password and this function works fine (if I remove line no:3)
// Update Password
func changePassword(password string, principal string) {
cmd := exec.Command("kadmin.local", "-q", "cpw "+principal)
cmd.Stdin = strings.NewReader(password)
cmd.Stdin = strings.NewReader(password) // Remove when one password require.
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
check(err)
fmt.Println(out.String())
}
I tried other method https://stackoverflow.com/a/10953142/3082827 but I am not able to figure how to make this work.