执行指定命令 @param command 命令 @return 命令执行完成返回结果 @throws IOException 失败时抛出异常,由调用者捕获处理
(String command)
| 20 | * @throws IOException 失败时抛出异常,由调用者捕获处理 |
| 21 | */ |
| 22 | public static String exeCommand(String command) throws IOException { |
| 23 | try ( |
| 24 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 25 | ) { |
| 26 | int exitCode = exeCommand(command, out); |
| 27 | if (exitCode == 0) { |
| 28 | System.out.println("命令运行成功!"); |
| 29 | } else { |
| 30 | System.out.println("命令运行失败!"); |
| 31 | } |
| 32 | return out.toString(DEFAULT_CHARSET); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * 执行指定命令,输出结果到指定输出流中 |
nothing calls this directly
no outgoing calls
no test coverage detected