/** Run thread */ private void startRead() { // While to end while (true) { try { mProcess.exitValue(); // read last read(); break; } catch (IllegalThreadStateException e) { read(); } Tools.sleepIgnoreInterrupt(50); } // Read end int len; if (mInStream != null) { try { while (true) { len = mInStream.read(BUFFER); if (len <= 0) break; } } catch (IOException e) { e.printStackTrace(); } } // Close destroy and done the read close(); destroy(); isDone = true; }
/** * Get Result * * @return Result */ protected String getResult() { // Until read end while (!isDone) { Tools.sleepIgnoreInterrupt(500); } // Get return value if (mResult.length() == 0) return null; else return mResult.toString(); }
/** * Run * * @param param param eg: "/system/bin/ping -c 4 -s 100 www.qiujuer.net" */ protected static CommandExecutor create(int timeout, String param) { String[] params = param.split(" "); CommandExecutor processModel = null; try { LOCK.lock(); Process process = PRC.command(params).redirectErrorStream(true).start(); processModel = new CommandExecutor(process, timeout); } catch (IOException e) { e.printStackTrace(); } finally { // Sleep 10 to create next Tools.sleepIgnoreInterrupt(10); LOCK.unlock(); } return processModel; }