Consider the following command in bash:
multi-bleu.perl reference < mt-output
I have two questions:
- What exactly happens here? My understanding is that
referenceandmt-outputare not arguments, but they are somehow written tostdin. So if they are files, will their contents be written tostdin? - How can I run this in a Python script, and get the result of the Perl script?
My attempt below doesn't work. Included in a file test.py:
from subprocess import Popen, PIPE
import settings
command = settings.BLEU + " " + settings.CORPUS + " < " + settings.HYPOTHESIS
print command
pipe = Popen(command, stdin=PIPE, stdout=PIPE)
output = pipe.communicate()[0]
print output
I run the command printed in the same folder as I run test.py. The former works, the latter doesn't. The error traceback is given below:
Traceback (most recent call last):
File "/Users/[...]/tests.py", line 6, in <module>
pipe = Popen([command], stdin=PIPE, stdout=PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory