我正在尝试使用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()
最佳答案
使用subprocess.Popen:
subprocess.Popen(['youtube-upload', '...'], shell=True, cwd='/Path/to/dst')
'cwd'参数是您想要的。
关于python - 使用python脚本调用cmd命令[youtube-upload],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43602269/