public static void main(String[] args) {
try {
Process pro = Runtime.getRuntime().exec("cmd /c java -version");
pro.waitFor();
BufferedInputStream br = new BufferedInputStream(pro.getInputStream());
BufferedInputStream br2 = new BufferedInputStream(pro.getErrorStream());
int ch;
System.out.println("Input Stream:");
while((ch = br.read())!= -1){
System.out.print((char)ch);
}
System.out.println("Error Stream:");
while((ch = br2.read())!= -1){
System.out.print((char)ch);
}
} catch (IOException e) {
e.printStackTrace();
}catch (InterruptedException e2) {
e2.printStackTrace();
}
}
java调用cmd命令并捕获执行结果字符串的代码
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java-长字符串加密
加密:为你的长字符串提供最高级别的保护!!!
加密算法 JAVA -
java中字符串拼接的多种方式
java中字符串拼接的多种方式
java 字符串拼接 -
c#执行cmd命令并获取返回结果字符串
n
cmd c# 命令 响应 结果 -
VC中调用CMD命令并获取调用结果
主要
句柄 全局变量 匿名管道