How do I replicate the following batch command using python subprocess module?
myprogram < myinput.in > myoutput.out
In other words, how do I run myprogram
using the contents of myinput.in
as the standard input and myoutput.out
as standard output?
The following should work:
myinput = open('myinput.in')
myoutput = open('myoutput.out', 'w')
p = subprocess.Popen('myprogram.exe', stdin=myinput, stdout=myoutput)
p.wait()
myoutput.flush()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.