I want to execute perforce command line "p4" from Go to do the login job. "p4 login" require user to input password.
How can I run a program that requires user's input in Go?
The following code doesn't work.
err = exec.Command(p4cmd, "login").Run()
if err != nil {
log.Fatal(err)
}
From the os/exec.Command docs:
// Stdin specifies the process's standard input. If Stdin is
// nil, the process reads from the null device (os.DevNull).
Stdin io.Reader
Set the command's Stdin field before executing it.
// To run any system commands. EX: Cloud Foundry CLI commands: `CF login`
cmd := exec.Command("cf", "login")
// Sets standard output to cmd.stdout writer
cmd.Stdout = os.Stdout
// Sets standard input to cmd.stdin reader
cmd.Stdin = os.Stdin
cmd.Run()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With