with open("stdout.txt","wb") as out, open("stderr.txt","wb") as err: subprocess.Popen("ls",stdout=out,stderr=err)