1 package org.objectweb.celtix.common.commands; 2 3 public class TestCommand { 4 5 private int result; 6 private int duration; 7 private String err; 8 private String out; 9 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 } 20 } else if ("-result".equals(args[i]) && i < (args.length - 1)) { 21 i++; 22 try { 23 result = Integer.parseInt(args[i]); 24 } catch (NumberFormatException ex) { 25 } 27 } else if ("-err".equals(args[i]) && i < (args.length - 1)) { 28 i++; 29 err = args[i]; 30 } else if ("-out".equals(args[i]) && i < (args.length - 1)) { 31 i++; 32 out = args[i]; 33 } else { 34 result = -1; 35 System.err.println("Usage: TestCommand [-duration <duration>] [-result <result>]" 36 + " [-out <out>] [-err <err>]"); 37 break; 38 } 39 i++; 40 } 41 } 42 43 void execute() { 44 45 if (null != out) { 46 System.out.println(out); 47 } 48 if (null != err) { 49 System.err.println(err); 50 } 51 try { 52 Thread.sleep(duration * 1000); 53 } catch (InterruptedException ex) { 54 } 56 System.exit(result); 57 } 58 59 public static void main(String [] args) { 60 TestCommand tc = new TestCommand(args); 61 tc.execute(); 62 } 63 } 64 | Popular Tags |