简体   繁体   中英

How to pass variable as filename in subprocess.call(…) in Python?

I am trying to call the following commands in Python. Basically, I want to substitute the second filename with customfilename .

 customfilename = "this is me"
 call ("MP4Box -add video.h264 " + customfilename, shell=True)

I get the following error:

Error - 2 input names specified, please check usage

What is the correct way to pass a variable to the call(....) command?

尝试将文件名放在字符串中并用引号引起来:

call ('MP4Box -add video.h264 "{}"'.format(customfilename), shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM