golang,如何执行需要用户输入的命令

前端之家收集整理的这篇文章主要介绍了golang,如何执行需要用户输入的命令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从Go执行perforce命令行“p4”来执行登录作业. “p4登录”要求用户输入密码.

如何在Go中运行需要用户输入的程序?

以下代码不起作用.

err  = exec.Command(p4cmd,"login").Run()
if err != nil {
    log.Fatal(err)
}
来自 os/exec.Command文档:
// Stdin specifies the process's standard input. If Stdin is
// nil,the process reads from the null device (os.DevNull).
Stdin io.Reader

在执行命令之前设置命令的Stdin字段.

猜你在找的Go相关文章