使用python脚本调用cmd命令[youtube-upload]

时间:2017-04-25 05:23:54

标签: python python-2.7 batch-file cmd youtube

我尝试使用python脚本调用cmd命令[youtube-upload]。如何使用批处理文件运行代码来处理特定文件夹中的所有文件?

import csv
import subprocess

def upload(csvfile):
    with open(csvfile) as f:
        for info in csv.DictReader(f):
            info.update({'client-secrets':'client_secrets.json', 'credentials-file':'client_secrets.json'})
            commandline = ['youtube-upload'] + ['--{0}="{1}"'.format(k,v) for k,v in info.items()]
            #print commandline
            subprocess.call(commandline) 

def main():
    import argparse
    p = argparse.ArgumentParser(description='youtube upload the media files specified in a CSV file')
    p.add_argument('-f', '--csvfile', default='vids.csv', 
        help='file path of CSV file containing list of media to upload')
    args = p.parse_args()

    upload(args.csvfile)

if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:0)

使用subprocess.Popen:

subprocess.Popen(['youtube-upload', '...'], shell=True, cwd='/Path/to/dst')

' cwd'争论就是你想要的。