子进程的IOError

时间:2016-12-11 06:23:59

标签: python subprocess senna

我正在尝试使用SENNA和python。我得到以下IOError

Traceback (most recent call last):
  File "C:\Python27\senna_test.py", line 18, in <module>
    tagged = StringIO(p.communicate(sentence)[0])
  File "C:\Python27\lib\subprocess.py", line 479, in communicate
    return self._communicate(input)
  File "C:\Python27\lib\subprocess.py", line 718, in _communicate
    self.stdin.write(input)
IOError: [Errno 22] Invalid argument

我的代码如下:

import os
import csv
from StringIO import StringIO
import subprocess as sp
from nltk.draw.tree import Tree, TreeWidget
from nltk.draw.util import CanvasFrame

senna_path="C:/Python27/senna/"
sentence = 'My brother has a dog'

# read senna output
p = sp.Popen(['blabla', '-path',  senna_path],
             executable=os.path.join(senna_path, 'senna-win32.exe'),
             stdin=sp.PIPE,
             stdout=sp.PIPE,
             stderr=sp.PIPE)
tagged = StringIO(p.communicate(sentence)[0])
table = csv.reader(tagged, dialect='excel-tab')

1 个答案:

答案 0 :(得分:0)

相反,你可以使用这种方法

https://ronan.collobert.com/senna/download.html

下载番泻叶

如果您正在使用Windows,那么:

python run .exe app with argument

直接使用senna-win32.exe

import subprocess
myinput = open('in.txt')
myoutput = open('out.txt', 'w')
p = subprocess.Popen('senna-win32.exe', stdin=myinput, stdout=myoutput)
p.wait()
myoutput.flush()

现在解析out.txt以获得结果。