go version go1.15.6 windows/amd64 dev os Windows [版本 10.0.19041.630]
我有一个 Go 应用程序,我在其中使用 exec.Cmd.Run() 运行 AWS CLI。我构建了 Cmd 类并填充了参数。
在运行 Cmd 之前,我使用 .String() 方法查看要运行的命令。如果我采用此值,将其复制到 shell,则命令执行时不会对提供给我的输出进行任何修改,也不会报告任何问题。
但是,当我运行该命令时,它无法返回错误。当我调试脚本时,它失败了,因为它说 AWS CLI 说参数不正确。
问题:
是否可以看到正在运行的内容的 100% 原始表示?它与 .String() 的返回值不匹配
有没有更好的方法来调用我缺少的操作系统级别命令?
真实例子:
cmd := &exec.Cmd{
Path: awsPath,
Args: args,
Stdout: &stdout,
Stderr: &stderr,
}
fmt.Printf("Command: %s\n", cmd.String())
// c:\PROGRA~1\Amazon\AWSCLIV2\aws.exe --profile testprofile --region us-east-1 --output json ec2 describe-network-interfaces --filters Name=group-id,Values=sg-abc123
// Running above works 100% of the time if ran from a shell window
err := cmd.Run()
// always errors out saying the format is incorrect
GoPlayground 复制问题 https://play.golang.org/p/mvV9VG8F0oz
一只甜甜圈
犯罪嫌疑人X
蝴蝶不菲
随时随地看视频慕课网APP
相关分类