工程中需要用到ffmpeg,想直接用exec包调用shell命令。本来以为很简单,结果折腾了一下午,最后查到了解决方案。
假如之前执行报错的语句为:
cmd := exec.Command("echo", "'helloworld!'")
out, err := cmd.Output()
c := "echo hello world"
cmd := exec.Command("sh", "-c", c)
out, err := cmd.Output()
即可!
感谢万能的stack overflow
reference:
https://stackoverflow.com/questions/20437336/how-to-execute-system-command-in-golang-with-unknown-arguments/20438245#20438245?newreg=80e5ccfd4f7f447c9acc931f5509af2b