blob: 821c8f6a3ac9db8310c92ca028f6d963f999ebdf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package main
import (
"os"
"os/exec"
)
// Execute the given string as a shell command and return the resulting output
func passwordCmd(password_cmd string) (password string, err error) {
shell := os.Getenv("SHELL")
// `Command` requires us to pass shell arguments as parameters to the
// function, but we don't know what the arguments are because
// `password_cmd` is an arbitrary command. To get around this, we pass the
// password command to the current shell to execute.
output, err := exec.Command(shell, "-c", password_cmd).Output()
if err != nil {
return "", err
}
return string(output), nil
}
|