简体   繁体   中英

converting _io.BufferedReader to str for write()

how can I get my write() function to accept my stdout = subprocess.PIPE output? I keep getting a Type Error problem.

this is my code:

with open("logger.txt","w") as fobj:                                         
    baby = subprocess.Popen('bash arguments', stdout = subprocess.PIPE,  shell = True)
    fobj.write(baby.communicate())

i get type error

and i tried with this, no error but the file is always empty

with open("logger.txt","w") as fobj:                                         
    baby = subprocess.Popen('bash arguments', stdout = subprocess.PIPE,  shell = True)
    baby.communicate()

can anyone help me? thanks

If you just want the script's output to be written to fobj ,

with open("logger.txt","wb") as fobj:                                         
    subprocess.check_call('bash arguments', stdout=fobj, 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