Search code examples
pythoncommand-linevlcpopen

Python: Inserting command line arguments from a variable length list


I'm joining up a few videos with VLC. However the number of videos I'm joining varies. I've been able to get it to work with a constant amount of variables in my output file list with:

p = sub.Popen(['C:\\Program Files\\VideoLAN\\vlc\\vlc.exe',
           outputFileList[0],
           outputFileList[1],
           outputFileList[2],
           'vlc://quit',
           '--sout-keep',
           '--sout=#gather:standard{access=file,dst=D:\\movies\\' + fileName + '.mov}',
           '--sout-keep'],
           stdout=sub.PIPE,
           stderr=sub.PIPE)

However I'm having trouble figuring out how to provide a varying number of arguments. Sometimes I want to joint 2 videos, sometimes 3, etc. I can't simply loop through and add items in the command line itself (at least I gave it a go). And I can't just provide a list in place of the individual items since it's looking for a string path for each.

Any help would be appreciated.


Solution

  • Just concatenate your lists:

    p = sub.Popen(['C:\\Program Files\\VideoLAN\\vlc\\vlc.exe'] + 
                  outputFileList +
                  ['vlc://quit',
                   '--sout-keep',
                   '--sout=#gather:standard{access=file,dst=D:\\movies\\' + fileName + '.mov}',
                   '--sout-keep'],
                  stdout=sub.PIPE,
                  stderr=sub.PIPE)