简体   繁体   English

如何使用python subprocess.call将标准输出定向到字符串而不是文件

[英]How to direct standard output to string instead of file with python subprocess.call

The following questions regard how to write subprocess.call to output files. 以下问题与如何将subprocess.call写入输出文件有关。

Question1 问题1

Question2 问题2

Is there away to redirect standard output of subprocess.call() to a string object in python, instead of having to create a file? 是否可以将subprocess.call()的标准输出重定向到python中的字符串对象,而不必创建文件? For example, I would like to call the md5sum command, and simply save the results as a string. 例如,我想调用md5sum命令,并将结果简单保存为字符串。 Is there a way to forgo the file making step? 有没有办法放弃文件制作步骤?

当然,以类似的方式使用subprocess.check_output() (它具有与call相同的参数结构),它将为您返回输出作为字节字符串。

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

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