Search code examples
powershellbatch-filevlc

Pass dir output as argument to another command


I want to join .mp4 videos using VLC. The following command works nicely when entered into a Windows command prompt:

vlc input_1.mp4 input_2.mp4 --sout "#gather:std{access=file,dst=output.mp4}" --sout-keep

I would like to generalize this incantation so that I don't have to adjust the list of input files manually. I want all mp4 files in the current directory, in alphabetical order. Ideally something like this:

files = dir *.mp4 -b -o:n
vlc %files% --sout "#gather:std{access=file,dst=output.mp4}" --sout-keep

The first line obviously does not work like that. I played around with the command a bit, but things quickly become awkward when file names contain spaces or (gasp!) exclamation points. I also tried PowerShell (both Start-Process and &), but due to lack of experience could not figure it out...


Solution

  • If using powershell to generate that cmd command try below options

    executing from powershell:

    cmd /c "vlc $((dir *.mp4).Name -join ' ') --sout ""#gather:std{access=file,dst=output.mp4}"" --sout-keep"
    

    executing from cmd:

    powershell -c "echo ""vlc $((dir *.mp4).Name -join ' ') --sout ""#gather:std{access=file,dst=output.mp4}"" --sout-keep""" | cmd