我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

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

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.

近期文章

  • 在Google Cloud Build上部署Golang AppEngine会生成无限的版本
  • 如何在Go项目中使用LiteIDE?
  • 从我的边缘节点推送kafka消息的最佳方法是什么?
  • 单元测试不同的标志值
  • 通过在Golang中检查MongoDB中的多个属性值来检索项目列表
  • 比较Go中的多个struct字段
  • 文件夹中没有可构建的Go源文件
  • 通过外壳与SSH连接?
  • Go-包装记录器,以便在请求的每条消息中添加特定信息
  • Golang HTTP服务器请求异步还是同步?
  • 从Go中的SQL查询获取计数和结果
  • 如何在Golang的AWS Lambda中支持多个触发器?
  • golang TLS是否支持IE8?
  • 同时选择随时发送和接收频道
  • 在Go中嵌入脚本语言
  • 与TCP服务器的多个连接
  • 一旦被字节占用就无法释放内存。
  • 如何从JSON获取相同的哈希
  • 当goroutine争用超过3400时,为什么sync.Mutex会大大降低性能?
  • 为什么我不能从Golang中正确读取C常量?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华