繁体   English   中英

将_io.BufferedReader转换为str以进行write()

[英]converting _io.BufferedReader to str for write()

如何获取我的write()函数以接受我的stdout = subprocess.PIPE输出? 我不断收到类型错误问题。

这是我的代码:

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

我收到类型错误

我尝试了这个,没有错误,但文件始终为空

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

谁能帮我? 谢谢

如果您只想将脚本的输出写入fobj

with open("logger.txt","wb") as fobj:                                         
    subprocess.check_call('bash arguments', stdout=fobj, shell=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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