Java 如何从process.popen追加数据

Java 如何从process.popen追加数据,java,python,stanford-nlp,Java,Python,Stanford Nlp,我正在尝试运行下一个代码: import os import subprocess import sys p = subprocess.Popen(['java', '-mx2g', '-cp', '''*''', 'edu.stanford.nlp.scenegraph.RuleBasedParser', ], stdin=subprocess.PIPE,stdout=subprocess.PIPE) out, err = p.communicate('the brown cat chase

我正在尝试运行下一个代码:

import os
import subprocess
import sys

p = subprocess.Popen(['java', '-mx2g', '-cp', '''*''', 'edu.stanford.nlp.scenegraph.RuleBasedParser', ], stdin=subprocess.PIPE,stdout=subprocess.PIPE)
out, err = p.communicate('the brown cat chased the white fox\n')
它使用斯坦福大学的核心NLP,一旦subprocess.Popen()行运行,算法将等待我使用communicate()发送的输入,我希望在变量our中获得我的输出,但结果是无,尽管在观察终端时,我看到了正确的输出:

Processing from stdin. Enter one sentence per line.
> [main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator tokenize
[main] INFO edu.stanford.nlp.pipeline.TokenizerAnnotator - TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator ssplit
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator parse
[main] INFO edu.stanford.nlp.parser.common.ParserGrammar - Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... 
done [3.3 sec].
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator lemma
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [5.9 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... done [2.0 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz ... done [3.2 sec].
[main] INFO edu.stanford.nlp.time.JollyDayHolidays - Initializing JollyDayHoliday for SUTime from classpath edu/stanford/nlp/models/sutime/jollyday/Holidays_sutime.xml as sutime.binder.1.
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/defs.sutime.txt
Jun 30, 2018 6:11:08 PM edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor appendRules
INFO: Read 83 rules
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.sutime.txt
Jun 30, 2018 6:11:11 PM edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor appendRules
INFO: Read 267 rules
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.holidays.sutime.txt
Jun 30, 2018 6:11:12 PM edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor appendRules
INFO: Read 25 rules
source              reln                target              
---                 ----                ---                 
cat-3               chase               fox-7               


Nodes               
---                 
cat-3               
  -brown               
fox-7               
  -white               

------------------------
> Exception in thread "main" java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Scanner.java:1540)
    at edu.stanford.nlp.scenegraph.RuleBasedParser.main(RuleBasedParser.java:253)

您似乎从标准错误流中获得了此输出

如果要捕获它,应该将
stderr=subprocess.PIPE
参数添加到
Popen()
调用中,它将在
err
变量中可用