zt ele
zt ele

Reputation: 11

exec.Command and terminal execution results are different

I want to use tf in my Go program. Like this:

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)
    }
}

but I always get the result:

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

when I run the command in terminal it works:

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

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

Upvotes: 1

Views: 64

Answers (1)

Adrien
Adrien

Reputation: 36

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

What if you try to execute that shell file manually?

You might also want to dump the HTTP traffic and figure out any notable difference. This can be done with tcpdump: tcpdump -A -vvv port 8080

The issue might also be related to the fact that your child process has its stdin connected to /dev/null, so if the binary is expecting to read anything there the behaviour will differ with running it from a shell manually (where the child process inherits your shell's stdin).

Upvotes: 1

Related Questions