List of usage examples for java.lang Process getInputStream
public abstract InputStream getInputStream();
From source file:com.hp.test.framework.jmeterTests.GetJmeterTestCaseFileList.java
private static int runProcess(String command) throws Exception { Process pro = Runtime.getRuntime().exec(command); printLines(command + " stdout:", pro.getInputStream()); printLines(command + " stderr:", pro.getErrorStream()); pro.waitFor();//from w w w .j a v a 2 s.c o m // System.out.println(command + " exitValue() " + pro.exitValue()); return pro.exitValue(); }
From source file:Main.java
public static String runCommand(String[] command, String workdirectory) { String result = ""; //AbLogUtil.d(AbAppUtil.class, "#"+command); try {/*w w w.j a v a2 s. com*/ ProcessBuilder builder = new ProcessBuilder(command); // set working directory if (workdirectory != null) { builder.directory(new File(workdirectory)); } builder.redirectErrorStream(true); Process process = builder.start(); InputStream in = process.getInputStream(); byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { String str = new String(buffer); result = result + str; } in.close(); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static BufferedReader runBufferedCommand(String cmd) throws IOException { Log.d(TAG, "Executing: " + cmd); Process process = Runtime.getRuntime().exec(cmd); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); return reader; }
From source file:Main.java
public static String getLinuxVersion() { try {//ww w . j a va2 s.c o m Process process = Runtime.getRuntime().exec("cat /proc/version"); InputStream outs = process.getInputStream(); InputStreamReader isrout = new InputStreamReader(outs); BufferedReader brout = new BufferedReader(isrout, 8 * 1024); String result = ""; String line; while ((line = brout.readLine()) != null) { result += line; } if (result != "") { String keyWord = "version "; int index = result.indexOf(keyWord); line = result.substring(index + keyWord.length()); index = line.indexOf(" "); return line.substring(0, index); } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getSDRoot() { String pre = null;// w w w . j a v a 2s . c o m String root = null; try { Runtime r = Runtime.getRuntime(); Process p = r.exec("ls mnt"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String inline; while ((inline = br.readLine()) != null) { if (inline.contains("mmcblk")) { pre = inline; break; } } br.close(); root = "/mnt/" + pre + "/" + pre + "p1"; } catch (Exception e) { } return root; }
From source file:Main.java
/** * Run a command and return its output./* w ww. j a v a 2 s .c o m*/ */ public static String systemOut(String command) throws Exception { int c; String cmd[] = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder s = new StringBuilder(); while ((c = r.read()) != -1) s.append((char) c); p.waitFor(); return s.toString(); }
From source file:de.micromata.mgc.application.webserver.config.KeyTool.java
public static void generateKey(ValContext ctx, File keyFile, String storePass, String keyAlias) { String[] args = { "keytool", "-genkey", "-alias", keyAlias, "-keyalg", "RSA", "-keystore", keyFile.getAbsolutePath(), "-keysize", "2048", "-keypass", storePass, "-storepass", storePass, "-dname", "cn=Launcher, ou=MGC, o=Microamta, c=DE" }; StringBuilder oksb = new StringBuilder(); oksb.append("Execute: " + StringUtils.join(args, " ")); try {//from w w w. jav a 2 s. co m ProcessBuilder pb = new ProcessBuilder(args); pb.redirectErrorStream(true); Process process = pb.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { oksb.append(line); } boolean success = process.waitFor(5, TimeUnit.SECONDS); if (success == false) { ctx.directError(null, "Fail to wait for keytool"); } else { int exitValue = process.exitValue(); if (exitValue == 0) { oksb.append("\nSuccess"); ctx.directInfo(null, oksb.toString()); } else { ctx.directError(null, oksb.toString()); ctx.directError(null, "Failure executing keytool. ReturnCode: " + exitValue); } } } catch (Exception ex) { ctx.directError(null, "Failure executing keytool: " + ex.getMessage(), ex); } }
From source file:Main.java
/** * Run a command and return its output.//from w ww . ja v a2s. co m */ public static String systemOut(String command) throws Exception { int c; String[] cmd = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder s = new StringBuilder(); while ((c = r.read()) != -1) { s.append((char) c); } p.waitFor(); return s.toString(); }
From source file:Main.java
public static String do_exec(String cmd) { String s = "/n"; try {//from www. ja v a 2 s. c om Process p = Runtime.getRuntime().exec(cmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { s += line + "/n"; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; }
From source file:Main.java
public static String exec(String cmd) { StringBuilder sb = new StringBuilder(); try {//from w ww .j a v a 2s . c o m Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } br.close(); if (process.waitFor() != 0) { System.err.println("exit value = " + process.exitValue()); } } catch (Exception e) { e.printStackTrace(); } return sb.toString(); }