无法使用exec在Go中为docker运行netstat

Trying to run terminal commands in Go using exec to get docker network usage but unable to. The following link shows how to get docker container's network usage using terminal and it works fine in terminal but not using Go. https://docs.docker.com/config/containers/runmetrics/

I get exit code 1, 2, 125, etc. with different combinations.

stdin, err := cmd.StdinPipe()
if err != nil {
    log.Fatal(err)
}

defer stdin.Close()
io.WriteString(stdin, "CID="+CID) // container ID
io.WriteString(stdin,"TASKS=/sys/fs/cgroup/devices/docker/$CID*/tasks")
io.WriteString(stdin, "PID=$(head -n 1 $TASKS)")
io.WriteString(stdin, "mkdir -p /var/run/netns")
io.WriteString(stdin, "ln -sf /proc/$PID/ns/net /var/run/netns/$CID")
io.WriteString(stdin, "ip netns exec $CID netstat -i")

out, err := cmd.CombinedOutput()
if err != nil {
    log.Fatal(err)
}

fmt.Printf("%s
", out)

Expected output:

Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1450  1228323      0      0 0       1761314      0      0      0 BMRU

If someone looks for the same in the future, here's a working solution

cmd := exec.Command("/bin/sh", "-c", "CID="+CID+" ; TASKS=/sys/fs/cgroup/devices/docker/$CID*/tasks ; PID=$(head -n 1 $TASKS); mkdir -p /var/run/netns ; ln -sf /proc/$PID/ns/net /var/run/netns/$CID ; ip netns exec $CID netstat -i")
out, err := cmd.CombinedOutput()
if err != nil {
    fmt.Println(err)
}

fmt.Printf("%s
", out)