0
stdout에 파일 객체를 사용하여 subprocess.Popen() 생성자를 실험하려고했습니다. 아래 코드를 실행하면 파일이 만들어 지지만 내용은 콘솔에 표시되지 않습니다. 내가 빠진 것을 나는 이해할 수 없다. 누구든지 내 실수를 지적 할 수 있습니까?'stdout = file_object'내용을 파일에서 읽을 수 없습니다.
file_name = "abc.txt"
fo = open(file_name, 'w')
cmd = 'dir'
child = subprocess.Popen(cmd, stdout=fo, stderr=fo, shell=True)
fo.close()
with open(file_name, 'r') as fo: print(fo.read())