Executing command with spaces in one of the parts

前端 未结 2 1690
囚心锁ツ
囚心锁ツ 2021-01-23 20:04

I am running a command through the os/exec package that is called like this:

out, err := Exec(\"ffprobe -i \'/media/Name of File.mp3\' -show_entries format=dura         


        
2条回答
  •  独厮守ぢ
    2021-01-23 20:56

    Well, I figured it out.

    var parts []string
    preParts := strings.FieldsFunc(command, f)
    for i := range preParts {
        part := preParts[i]
        parts = append(parts, strings.Replace(part, "'", "", -1))
    }
    

    I needed to remove the single quotes from the arg passed into the exec.Command function.

提交回复
热议问题