开发者

using pipe with python

import re
import subprocess

sub = subprocess.Popen(['/home/karthik/Downloads/stanford-parser-2011-06-   08/lexparser.csh'], stdin=subprocess.PIPE, stdout=subprocess.PIP开发者_JAVA百科E, 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()


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜