gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 02:06:32 32 4
gpt4 key购买 nike

我想在我的 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com