2011-06-15 81 views
0
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() 

所以我想斯坦福解析器和使用lexparser.csh来解析这行文本。但是当我运行这段代码时,我得到了默认文本的输出。给出的实际文本不被解析。那么,我是否正确地使用了管道?我已经在很多示例中看​​到了 - ' - '与命令一起使用。为什么被使用?当我使用该脚本只是在sub.stdout.readline()使用管道与python

+0

白天('08')之前的空间是否显着? – 2011-06-15 12:49:16

+0

不,没有空间不重要。我只是知道如何格式化它! – 2011-06-15 12:49:58

+0

确保管道比python大,否则可能发生死锁。 ;-P – Macke 2011-06-15 12:54:53

回答

1

停止脚本您可能需要在sub.stdin拨打电话flush()后写。

+0

nope..just试过,是否还有其他什么是错误的脚本? – 2011-06-15 12:56:05