我需要在golang代码中使用lxd-p2c( https://github.com/lxc/lxd/tree/master/lxd-p2c )。
我尝试将密码传递给lxd-p2c由上述代码构建的二进制文件,该二进制文件使用term.ReadPassword(0)(https://github.com/lxc/lxd/blob/master/lxd-p2c/utils.go#L166)在Linux中读取密码。
我在互联网上进行了一些搜索并尝试了以下代码,但它们不起作用。
# 1
cmd := exec.Command(command, args...)
cmd.Stdin = strings.NewReader(password)
# 2
cmd := exec.Command(command, args...)
stdin, _ := cmd.StdinPipe()
io.WriteString(stdin, password)
Run Code Online (Sandbox Code Playgroud)
类似但简单的测试代码:https://play.golang.org/p/l-9IP1mrhA(代码来自/sf/answers/2293793561/)
构建二进制文件并在 go 中调用它。
编辑:
没有找到解决方法,我term.ReadPassword(0)在源代码中删除了。