Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using files as stdin and stdout for subprocess

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?

like image 703
Nolander Avatar asked Mar 01 '13 22:03

Nolander


1 Answers

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() 
like image 95
Elmar Peise Avatar answered Oct 09 '22 07:10

Elmar Peise