我正在使用 subprocess 从 /dev/random 使用 unix dd 创建一个随机文件。现在,如果我希望将 dd 的数据输出写入文件而不是标准输出。所以这是我正在使用的代码,
import subprocess
out_fd = open('test_file','w')
def os_system_dd():
global out_fd
out_fd.write("executing the time dd command\n")
cmd_list = ['time','dd','if=/dev/random', 'of=/home/anand/sys_entropy_random', 'bs=1M' ,'count=5']
a = subprocess.Popen(cmd_list,stdout=out_fd)
a.wait()
if __name__ == '__main__':
os_system_dd()
这不会将 dd 输出打印到文件中,而是将其打印到标准输出中。这是 dd 命令的特定功能吗?或者我错过了一些关于子流程如何工作的东西?