0

I have an array of paths that I would like to pipe into another command.

For example, say I have the following array of paths of unknown length N:

file1.mp4
file2.mp4
file3.mp4
fileN.mp4

That are stored in a []string

Of which, I am trying to pipe into the following command:

mpv --playlist=-

Resulting in:

file1.mp4 file2.mp4 file3.mp4 fileN.mp4 | mpv --playlist=-

So that an mpv instance is launched playing the files in order.

1

1 Answer 1

1

Thanks Steffen, for leading me in the right direction.

Here's my solution:

var str string
for _, path  := range paths {
    str += path + "\n"
}

cmd := exec.Command("mpv", "--playlist=-")
cmd.Stdin = strings.NewReader(str)

err := cmd.Run()
Sign up to request clarification or add additional context in comments.

1 Comment

cmd.Stdin = strings.NewReader(strings.Join(paths, "\n"))