Java 命令行使用梳理

Java 命令行代码

Java 调用命令行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Process p;
String cmds = "ipconfig /all";

try {
// 执行命令
p = Runtime.getRuntime().exec(cmds);
// 获取输出流,并包装到 BufferedReader 中
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while((line=br.readLine()) != null) {
System.out.println(line);
}
int exitVal = p.waitFor();
System.out.println("进程返回值:" + exitVal);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022 qusong
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信