Go

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

发布于 2021-02-01 10:41:37

我想从Go执行perforce命令行“ p4”以执行登录工作。“ p4登录”要求用户输入密码。

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

以下代码不起作用。

err  = exec.Command(p4cmd, "login").Run()
if err != nil {
    log.Fatal(err)
}
关注者
0
被浏览
99
1 个回答
  • 面试哥
    面试哥 2021-02-01
    为面试而生,有面试问题,就找面试哥。

    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字段。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看