我正在尝试使用aws cli列出s3上的目录内容。当我在终端中运行我的命令时,它可以正常配置cli。但是,当我尝试使用exec.Command()运行它时,输出()它不起作用。
代码:
package main
import (
"fmt"
"os/exec"
)
const (
bucketName = "some-bucket"
dirPath = "data/entity/"
)
func main() {
s3Path := bucketName + "/" + dirPath
output, err := exec.Command("aws", "s3 ls s3://"+s3Path+" --recursive").Output()
if err != nil {
fmt.Println(err)
}
fmt.Println(output)
}
标准输出:
exit status 2
[]