output = cStringIO.StringIO()
output.write('string') # this emulates some_file.txt
p = subprocess.Popen(['perl', 'file.pl'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
line, _ = p.communicate(output.getvalue())
print line
output.close()
This prints Can't open perl script "file.pl": No such file or directory
. The python script and perl file are in the same directory!
I want line
to be the output of perl file.pl < some_file.txt
How to do this?