Question

import re
import subprocess

sub = subprocess.Popen(['/home/karthik/Downloads/stanford-parser-2011-06-   08/lexparser.csh'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr = subprocess.PIPE)

sub.stdin.write("i am a fan of ac milan which is the best club in the world")

relns = []

while(True):
    rel = sub.stdout.readline()
        m = re.search("Sentence skipped", rel)

    if m != None:
            print 'stop'
            sys.exit(0)

        if rel == '\n':
                break
        relns.append(rel) 

print relns

sub.terminate()

So i want to the stanford parser and using the lexparser.csh to parse this line of text . But when i run this piece of code i am a getting the output of the default of text. The actual text given in is not being parsed. So am i using pipes the right way ?And i've seen in a lot of examples - a '-' is used along with the command . Why is that being used ? Cos when i use that the script just stalls at sub.stdout.readline()

Was it helpful?

Solution

You may need to call flush() on sub.stdin after writing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top