简体   繁体   中英

Python's subprocess.check_output( )

I'm working with python's subprocess.check_output() and I'm using it to run a python file that takes certain attributes (like fileName, title, etc..). Everything works fine however, I decided to pass in a string variable instead of an actual string. This doesn't work and I'm not sure why. Does anyone see something that I don't?

import textFile
import upload
import subprocess
def upload(fileName):
    arr = []
    bunny = "big_buck_bunny.flv" #this is the variable
    arr = textFile.readLine(fileName)
    size = textFile.getLines(fileName)
    i = 0
    while(i < size):
        f = open("upload.py-oauth2.json", 'w').close()
        textFile.append("C:\\Users\\user1\\Desktop\\tester\\upload.py-oauth2.json",arr[i])
        #This below is where i would like to pass in a variable
        subprocess.check_output('python upload.py --file="C:\\Users\\...\\anniebot\\' + bunny)
    i+=1


upload("C:\\Users\\user1\\Desktop\\tester\\accountList.txt")        

So I pretty much would like to change the path constantly. The problem is, I cant figure out a way to get subprocess to work without passing in a fixed string.

i would like to do something like:-

    subprocess.check_output('python upload.py --file="C:\\Users\\user1\\Videos\\anniebot\\" + bunny --title="title" --description="testing" --keywords="test" --category="22" --privacyStatus="public"')

Do you mean:

subprocess.check_output('python upload.py --file="C:\\Users\\...\\anniebot\\' + bunny + '" --title= ...')

So basically concatenate the string using the single quote instead of the double quote you are using.

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