Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.InputStream; import android.util.Log; public class Main { public static String runCommand(String[] command, String workdirectory) { String result = ""; Log.d("AppUtil.class", "#" + command); try { 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; } }