This is a bug in chasen. When run through Python, you can see the following syscalls it issues:
write(1, "\n", 1) = 1
read(0, "", 4096) = 0
write(1, "\n", 1) = 1
read(0, "", 4096) = 0
i.e. it does not correctly handle EOF. To fix this, simply affix a newline ('\n'
) to your Python string, like this:
# coding: utf-8
import os
from subprocess import Popen, PIPE
string = u"悪妻は百年の不作。"
env = dict(os.environ)
env['LC_ALL'] = 'en_US.UTF-8'
args = ['chasen', '-i u', '-F"%m "']
process = Popen(args, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env)
out, err = process.communicate(input=(string + u'\n').encode('utf-8'))
print(out)