source: greenstone3/trunk/src/java/org/greenstone/server/RunTarget.java@ 18690

Last change on this file since 18690 was 18558, checked in by davidb, 15 years ago

Restructuring of code to support a web server version for Greenstone2 and well as Greenstone3

File size: 1.5 KB
Line 
1package org.greenstone.server;
2
3import java.io.IOException;
4import java.io.BufferedReader;
5import java.io.InputStream;
6import java.io.InputStreamReader;
7
8import org.greenstone.server.StreamGobbler;
9
10import org.apache.log4j.*;
11
12public abstract class RunTarget extends Thread
13{
14 protected String targetCmd = "";
15 protected static Logger logger = Logger.getLogger(RunTarget.class.getName());
16
17 protected int state = -1; //success: 0 error: 1
18 public static int SUCCESS = 0;
19 public static int FAILED = 1;
20
21 protected String targetSuccess;
22 protected String targetFailed;
23 protected String targetFinished;
24
25 public void run()
26 {
27
28 try {
29 state = -1;
30 Runtime run = Runtime.getRuntime();
31
32 String targetCmd = getTargetCmd();
33 logger.info("Target: " + targetCmd);
34
35 Process process = run.exec(targetCmd);
36 BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
37 String line = null;
38 while (!(line = br.readLine()).startsWith(targetFinished)){
39
40 if (line.equals(targetSuccess)){
41 state = 0;
42 }
43
44 if (line.equals(targetFailed)){
45 state = 1;
46 }
47 logger.info(line);
48 }
49 } catch (Exception e) {
50 e.printStackTrace();
51 logger.error(e);
52 state = 1;
53 }
54 }
55
56 public int getTargetState()
57 {
58 return state;
59 }
60
61 public abstract void setTargetCmd(String cmd);
62
63 public String getTargetCmd()
64 {
65 return this.targetCmd;
66 }
67}
Note: See TracBrowser for help on using the repository browser.