Runtime调用
public class TestInvokeDosCommand {
private static Log log = LogFactory.getLog(TestInvokeDosCommand.class);
public static void main(String[] args) {
String antfile = "D:/公司相关/服务器更新/2016/HD";
String cmd = "./build2.bat";
try {
InputStream inputStream = process.getInputStream();
InputStreamReader isr = new InputStreamReader(inputStream);
InputStream errorStream = process.getErrorStream();
InputStreamReader esr = new InputStreamReader(errorStream);
int n1;
char[] c1 = new char[1024];
StringBuffer standardOutput = new StringBuffer();
while ((n1 = isr.read(c1)) > 0) {
standardOutput.append(c1, 0, n1);
}
System.out.println("Standard Output: " + standardOutput.toString());
int n2;
char[] c2 = new char[1024];
StringBuffer standardError = new StringBuffer();
while ((n2 = esr.read(c2)) > 0) {
standardError.append(c2, 0, n2);
}
System.out.println("Standard Error: " + standardError.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}