2012-07-04 46 views
4

我想从Go执行perforce命令行“p4”来完成登录工作。 “p4登录”要求用户输入密码。golang,如何执行需要用户输入的命令

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

以下代码不起作用。

err = exec.Command(p4cmd, "login").Run() 
if err != nil { 
    log.Fatal(err) 
} 

回答

4

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 

执行前将命令的标准输入字段。

+0

谢谢。有用。 – yongzhy

相关问题