我試着運行: java -jar /home/user/workspace/maltparser-1.8/maltparser-1.8.jar 這是工作。與迴歸:從exec運行java -jar
-----------------------------------------------------------------------------
MaltParser 1.8
-----------------------------------------------------------------------------
MALT (Models and Algorithms for Language Technology) Group
Vaxjo University and Uppsala University
Sweden
-----------------------------------------------------------------------------
Usage: java -jar maltparser-1.8.jar -f <path to option file> <options> java -jar maltparser-1.8.jar -h for more help and options
help ( -h) : Show options
----------------------------------------------------------------------------- option_file ( -f) : Path to option file
----------------------------------------------------------------------------- verbosity *( -v) : Verbosity level debug - Logging of debugging messages error - Logging of error events fatal - Logging of very severe error events info
- Logging of informational messages off - Logging turned off warn - Logging of harmful situations
-----------------------------------------------------------------------------
Documentation: docs/index.html
而現在,我嘗試從我的課運行此的.jar:
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
Process ps = Runtime.getRuntime().exec(new String[]{"java","-jar","/home/user/workspace/maltparser-1.8/maltparser-1.8.jar"});
ps.waitFor();
java.io.InputStream is=ps.getInputStream();
byte b[]=new byte[is.available()];
is.read(b,0,b.length);
System.out.println(new String(b));
}
}
,並返回我什麼......我想攔截輸出流。我如何做到這一點?
嘗試把'waitFor'後,您已經嘗試閱讀'InputStream',因爲[示例](http://stackoverflow.com/questions/15218892/running-a-java-program-from-another-java-program/15220419#15220419) – MadProgrammer 2014-10-30 03:50:35
它不工作太。 – bjabgcjrpxaf 2014-10-30 03:58:40
沒有冒犯,但你閱讀流的方法(恕我直言)是有點奇怪... – MadProgrammer 2014-10-30 04:00:45