IOError with subprocess

839 Views Asked by At

I am trying to use SENNA with python. I get the following 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

My code is as follows:

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

There are 1 best solutions below

0
On

instead you can use this approach

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

if you are using windows then:

python run .exe app with argument

use senna-win32.exe directly

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()

Now parse out.txt to get your results.