timonweb
timonweb

Reputation: 348

Spawning a docker command yields an empty result

I have the following Go code, where I try to spawn docker command and get its output:

package main

import "fmt"
import "os/exec"

func main() {
    cmd := exec.Command("docker")
    cmdOutput, err := cmd.Output()
    if (err != nil) {
        panic(err)
    }
    fmt.Println(string(cmdOutput))
}

But when I run this code as a result I get an empty string, which is stange since I get an output when I run docker command directly in a command line.

Moreover, this same code yields results just fine if I spawn other commands with it, for example ls.

What may be wrong here?

Upvotes: 0

Views: 78

Answers (1)

CallMeLoki
CallMeLoki

Reputation: 1361

try using cmd.CombinedOutput()

Upvotes: 3

Related Questions