go - exec.Command和终端执行结果不同

标签 go tfs

我想在我的 Go 程序中使用 tf。像这样:

func main() {
    cmd := exec.Command("tf", `workspace`, `-new`, `testsssss`, `-collection:http://xxx.xxx.xxx:8080/tfs/new/`, `-login:Administrator,op@ms2019`)
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    err := cmd.Run()
    if err != nil {
        panic(err)
    }
}

但我总是得到结果:

Error: Access is denied when connecting to the TFS server http://xxx.xxx.xxx:8080/ (authentication as an administrator)

当我在终端中运行命令时,它起作用了:

tf workspace -new testsss -collection:http://xxx.xxx.xxx:8080/tfs/new/ -login:Administrator,op@ms2019

我试着写成shell文件,然后用exec调用,还是失败。

最佳答案

I tried to write it to shell file, then use exec to call it, but it still failed.

如果您尝试手动执行该 shell 文件怎么办?

您可能还想转储 HTTP 流量并找出任何显着差异。这可以通过 tcpdump 完成:tcpdump -A -vvv port 8080

这个问题也可能与您的子进程将其标准输入连接到/dev/null 的事实有关,因此如果二进制文件期望在那里读取任何内容,则行为将与从 shell 手动运行它不同(其中子进程继承你的 shell 的标准输入)。

关于go - exec.Command和终端执行结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57550903/

相关文章:

regex - 跳过正则表达式字符,直到使用golang搜索

go - 如何在保留注释的情况下解析 golang 中的一般 yaml?

go - HTTP.Server 关闭导致运行时错误

visual-studio - 从 Visual Studio 解决方案中删除项目

mongodb - Golang MGO 模块是否锁定或解锁 Go 对象?

TFS 2018流程模板编辑器不见了?

git - tfs 服务器上的身份验证失败

c# - TFS API - 如何独立于它们属于哪个构建定义来查询构建

azure - 使用 TFS Azure 进行临时异地部署?

mongodb - 需要使用 $add 和 $gt 删除使用 mgo (Golang && MongoDB)