私はサブプロセスを使用して、unixddを使用して/dev/randomからランダムファイルを作成しています。ここで、ddのデータ出力をstdoutではなくファイルに書き込みたい場合。これが使用しているコードです、
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出力をファイルに出力せず、代わりにstdoutに出力します。これはddコマンドの特定の機能ですか?または、サブプロセスがどのように機能するかについて何かが欠けていますか?