comparison src/testKonoha/KonohaInvoker.java @ 3:178aeb91d108 draft default tip

add pom.xml
author one
date Mon, 04 Jun 2012 13:53:39 +0900
parents b101ee77e78c
children
comparison
equal deleted inserted replaced
2:b101ee77e78c 3:178aeb91d108
14 void runKonoha(String[] cmd) throws KonohaException { 14 void runKonoha(String[] cmd) throws KonohaException {
15 try { 15 try {
16 Runtime run = Runtime.getRuntime(); 16 Runtime run = Runtime.getRuntime();
17 Process p = run.exec(cmd); 17 Process p = run.exec(cmd);
18 in = p.getInputStream(); 18 in = p.getInputStream();
19 errin = p.getInputStream(); 19 errin = p.getErrorStream();
20 20
21 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 21 BufferedReader br = new BufferedReader(new InputStreamReader(in));
22 BufferedReader ebr = new BufferedReader( 22 BufferedReader ebr = new BufferedReader(new InputStreamReader(errin));
23 new InputStreamReader(errin));
24
25 String kout = readMessege(br); 23 String kout = readMessege(br);
26 String kerr = readMessege(ebr); 24 String kerr = readMessege(ebr);
25
27 p.waitFor(); 26 p.waitFor();
27
28 System.out.println(kerr);
29 System.out.println(kout);
28 30
29 System.out.println(kout); 31 if (kerr != "") {
30 System.out.println(kerr); 32 throw new KonohaException(kerr);
31
32 if (kerr != null) {
33 throw new KonohaException(kout);
34 } 33 }
35 34
36 } catch (IOException e) { 35 } catch (IOException e) {
37 e.printStackTrace(); 36 e.printStackTrace();
38 } catch (InterruptedException e) { 37 } catch (InterruptedException e) {
49 48
50 void invoke(String filename, String message) throws KonohaException { 49 void invoke(String filename, String message) throws KonohaException {
51 String[] cmd = {KONOHA, filename, message}; 50 String[] cmd = {KONOHA, filename, message};
52 runKonoha(cmd); 51 runKonoha(cmd);
53 } 52 }
54 void invoke(String[] messages) throws KonohaException { 53 void invoke(String filename, String[] messages) throws KonohaException {
54 int num = messages.length + 2;
55 String[] cmd = new String[num];
56 cmd[0] = KONOHA;
57 cmd[1] = filename;
58 for (int i=0; i < messages.length; i++) {
59 cmd[i+2] = messages[i];
60 }
61 runKonoha(cmd);
62 } void invoke(String[] messages) throws KonohaException {
55 int num = messages.length + 1; 63 int num = messages.length + 1;
56 String[] cmd = new String[num]; 64 String[] cmd = new String[num];
57 cmd[0] = KONOHA; 65 cmd[0] = KONOHA;
58 for (int i=0; i < messages.length; i++) { 66 for (int i=0; i < messages.length; i++) {
59 cmd[i+1] = messages[i]; 67 cmd[i+1] = messages[i];
66 String line = null; 74 String line = null;
67 while ((line = br.readLine()) != null) { 75 while ((line = br.readLine()) != null) {
68 str = str + line + "\n"; 76 str = str + line + "\n";
69 } 77 }
70 return str; 78 return str;
71
72 } 79 }
73 80
74 public static void main(String[] args) { 81 public static void main(String[] args) {
75 KonohaInvoker konoha = new KonohaInvoker(); 82 KonohaInvoker konoha = new KonohaInvoker();
76 String filename = "/Users/aotokage/hg/nobuyasu/konoha/test/math.k"; 83 String filename = "/Users/aotokage/hg/nobuyasu/konoha/test/math.k";
77 String message = ""; 84 String message = "64";
85 // String[] message = {"2","4"};
78 try { 86 try {
79 konoha.invoke(filename, message); 87 konoha.invoke(filename, message);
80 } catch (KonohaException e) { 88 } catch (KonohaException e) {
81 System.out.println(e); 89 System.out.println(e);
82 } 90 }
83 91
84 } 92 }
85 93
94
86 } 95 }