package utils;
import java.io.InputStreamReader;
public class Dos {
public static void main(String args[]) {
System.out.println("Hello utils.Dos!");
if (! isWindows()) {
System.out.println("sorry, this only works on windows now");
return;
}
Dos d = new Dos();
try {
d.command(
"c:\\My Documents"
+ "\\java\\book"
+ "\\settime.bat hello");
} catch (Exception e) {
e.printStackTrace();
}
}
public void command(String com)
throws java.io.IOException {
Runtime rt = Runtime.getRuntime();
Process p =
rt.exec(com);
System.out.println("process=" + p);
java.io.BufferedReader br
= new java.io.BufferedReader(
new InputStreamReader(
p.getInputStream()));
String s = null;
while ((s = br.readLine()) != null)
System.out.println("dos:" + s);
}
public static boolean isLinux() {
String os = System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("linux") ? true : false;
}
public static boolean isSolaris() {
String os = System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("sun") ? true : false;
}
public static boolean isWindows() {
String os = System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("win") ? true : false;
}
}