Using files as stdin and stdout for subprocess

前端 未结 1 1307
南方客
南方客 2020-12-14 16:42

How do I replicate the following batch command using python subprocess module?

myprogram < myinput.in > myoutput.out

In other words,

相关标签:
1条回答
  • 2020-12-14 17:25

    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()
    
    0 讨论(0)
提交回复
热议问题