/Users/lyon/j4p/src/utils/Dos.java
|
1 package utils;
2
3 // utils.Dos
4
5 import java.io.InputStreamReader;
6
7 public class Dos {
8 public static void main(String args[]) {
9 System.out.println("Hello utils.Dos!");
10 if (! isWindows()) {
11 System.out.println("sorry, this only works on windows now");
12 return;
13 }
14 Dos d = new Dos();
15 try {
16 d.command(
17 "c:\\dog.bat");
18 } catch (Exception e) {
19 e.printStackTrace();
20 }
21
22 }
23
24 public void command(String com)
25 throws java.io.IOException {
26 Runtime rt = Runtime.getRuntime();
27 Process p =
28 rt.exec(com);
29 System.out.println("process=" + p);
30 java.io.BufferedReader br
31 = new java.io.BufferedReader(
32 new InputStreamReader(
33 p.getInputStream()));
34 String s = null;
35 while ((s = br.readLine()) != null)
36 System.out.println("dos:" + s);
37 }
38
39 public static boolean isLinux() {
40 String os = System.getProperty("os.name");
41 return os != null && os.toLowerCase().startsWith("linux") ? true : false;
42 }
43
44 public static boolean isSolaris() {
45 String os = System.getProperty("os.name");
46 return os != null && os.toLowerCase().startsWith("sun") ? true : false;
47 }
48
49 public static boolean isWindows() {
50 String os = System.getProperty("os.name");
51 return os != null && os.toLowerCase().startsWith("win") ? true : false;
52 }
53
54 }
55