01: package org.objectweb.celtix.common.commands;
02:
03: public class TestCommand {
04:
05: private int result;
06: private int duration;
07: private String err;
08: private String out;
09:
10: public TestCommand(String[] args) {
11: int i = 0;
12: while (i < args.length) {
13: if ("-duration".equals(args[i]) && i < (args.length - 1)) {
14: i++;
15: try {
16: duration = Integer.parseInt(args[i]);
17: } catch (NumberFormatException ex) {
18: // leave at default
19: }
20: } else if ("-result".equals(args[i])
21: && i < (args.length - 1)) {
22: i++;
23: try {
24: result = Integer.parseInt(args[i]);
25: } catch (NumberFormatException ex) {
26: // leave at default
27: }
28: } else if ("-err".equals(args[i]) && i < (args.length - 1)) {
29: i++;
30: err = args[i];
31: } else if ("-out".equals(args[i]) && i < (args.length - 1)) {
32: i++;
33: out = args[i];
34: } else {
35: result = -1;
36: System.err
37: .println("Usage: TestCommand [-duration <duration>] [-result <result>]"
38: + " [-out <out>] [-err <err>]");
39: break;
40: }
41: i++;
42: }
43: }
44:
45: void execute() {
46:
47: if (null != out) {
48: System.out.println(out);
49: }
50: if (null != err) {
51: System.err.println(err);
52: }
53: try {
54: Thread.sleep(duration * 1000);
55: } catch (InterruptedException ex) {
56: // ignore
57: }
58: System.exit(result);
59: }
60:
61: public static void main(String[] args) {
62: TestCommand tc = new TestCommand(args);
63: tc.execute();
64: }
65: }
|