//打印截图命令 StringBuffer test = new StringBuffer(); for (int i = 0; i < commend.size(); i++) { test.append(commend.get(i) + " "); } System.out.println("截图命令:" + test);
//转码后完成截图功能-还是得用线程来解决 try { //调用线程处理命令 ProcessBuilder builder = new ProcessBuilder(); builder.command(commend); Process p = builder.start();
//获取进程的标准输入流 final InputStream is1 = p.getInputStream(); //获取进程的错误流 final InputStream is2 = p.getErrorStream(); //启动两个线程,一个线程负责读标准输出流,另一个负责读标准错误流 new Thread() { publicvoidrun(){ BufferedReader br = new BufferedReader( new InputStreamReader(is1)); try { String lineB = null; while ((lineB = br.readLine()) != null) { if (lineB != null) { //必须取走线程信息避免堵塞 //System.out.println(lineB); } } } catch (IOException e) { e.printStackTrace(); } //关闭流 finally { try { is1.close(); } catch (IOException e) { e.printStackTrace(); } }