Revision: 13833
http://gate.svn.sourceforge.net/gate/?rev=13833&view=rev
Author: markagreenwood
Date: 2011-05-18 18:44:39 +0000 (Wed, 18 May 2011)
Log Message:
-----------
upgraded the Tagger_Framework to use the ProcessManager and added support for
starting an external process from a specific directory
Modified Paths:
--------------
gate/trunk/plugins/Tagger_Framework/src/gate/taggerframework/GenericTagger.java
gate/trunk/src/gate/util/ProcessManager.java
Modified:
gate/trunk/plugins/Tagger_Framework/src/gate/taggerframework/GenericTagger.java
===================================================================
---
gate/trunk/plugins/Tagger_Framework/src/gate/taggerframework/GenericTagger.java
2011-05-18 12:30:53 UTC (rev 13832)
+++
gate/trunk/plugins/Tagger_Framework/src/gate/taggerframework/GenericTagger.java
2011-05-18 18:44:39 UTC (rev 13833)
@@ -18,10 +18,13 @@
import gate.util.BomStrippingInputStreamReader;
import gate.util.Files;
import gate.util.OffsetComparator;
+import gate.util.ProcessManager;
import gate.util.Strings;
import java.io.BufferedReader;
import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -101,6 +104,9 @@
// A copy of the inputTemplate with Java escape sequences like \t
// unescaped
protected String inputTemplateUnescaped;
+
+ //a util class for dealing with external processes, i.e. the tagger
+ private ProcessManager processManager = new ProcessManager();
/**
* This method initialises the tagger. This involves loading the pre
@@ -445,26 +451,18 @@
* @throws ExecutionException if an error occurs executing the tagger
*/
protected InputStream runTagger(String[] cmdline) throws ExecutionException {
- // TODO: replace this with the ProcessManager from gate.util
-
- // a handle to the process we are going to run
- Process p = null;
-
+
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
+
try {
if(taggerDir == null) {
- // if there is no dir specified just run the tagger
- p = Runtime.getRuntime().exec(cmdline);
+ processManager.runProcess(cmdline, baout, (debug ? System.err : null));
}
else {
- // if a dir is specified then make sure we run the tagger from
- // there otherwise it probably won't work
- p = Runtime.getRuntime().exec(cmdline, new String[] {},
- Files.fileFromURL(taggerDir));
+ processManager.runProcess(cmdline, Files.fileFromURL(taggerDir),
baout, (debug ? System.err : null));
}
-
- // return the input stream so that another method can read the
- // output from the tagger
- return p.getInputStream();
+
+ return new ByteArrayInputStream(baout.toByteArray());
}
catch(Exception e) {
throw new ExecutionException(e);
Modified: gate/trunk/src/gate/util/ProcessManager.java
===================================================================
--- gate/trunk/src/gate/util/ProcessManager.java 2011-05-18 12:30:53 UTC
(rev 13832)
+++ gate/trunk/src/gate/util/ProcessManager.java 2011-05-18 18:44:39 UTC
(rev 13833)
@@ -58,9 +58,14 @@
*/
public synchronized int runProcess(String[] argv, boolean dumpOutput)
throws IOException {
- return runProcess(argv, (dumpOutput ? System.out : null), (dumpOutput ?
System.err : null));
+ return runProcess(argv, null, (dumpOutput ? System.out : null),
(dumpOutput ? System.err : null));
}
+ public synchronized int runProcess(String[] argv, OutputStream out,
OutputStream err)
+ throws IOException {
+ return runProcess(argv, null, out, err);
+ }
+
/**
* Run the given external process. If an exception results from starting the
* process, or while reading the output from the process, it will be thrown.
@@ -71,14 +76,15 @@
* @param dumpOutput should we copy the process output and error streams to
* the Java output and error streams or just consume them silently?
*/
- public synchronized int runProcess(String[] argv, OutputStream out,
OutputStream err)
+ public synchronized int runProcess(String[] argv, File dir, OutputStream
out, OutputStream err)
throws IOException {
// Start the process. This may throw an exception
if(DEBUG) {
System.err.println("Starting process");
}
- Process proc = Runtime.getRuntime().exec(argv);
+ Process proc = Runtime.getRuntime().exec(argv, null, dir);
+
// set up the stream gobblers for stdout and stderr
if(DEBUG) {
System.err.println("Configuring gobblers");
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs