Skip to content

Instantly share code, notes, and snippets.

@CedricGatay
Created August 26, 2010 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricGatay/552267 to your computer and use it in GitHub Desktop.
Save CedricGatay/552267 to your computer and use it in GitHub Desktop.
package fr.gatay.cedric.android.bintools;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import android.util.Log;
public class ProcessUtils {
private static final boolean LOGD = true;
private static final String TAG = "ProcessUtils";
public static Vector<String> execute(Iterable<String> commands)
throws IOException, InterruptedException {
Vector<String> res = new Vector<String>();
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
// DataInputStream osRes = new
// DataInputStream(process.getInputStream());
for (String single : commands) {
if (LOGD) {
Log.d(TAG, "write " + single);
}
os.writeBytes(single + "\n");
if (LOGD) {
Log.d(TAG, "flush " + single);
}
os.flush();
// String s = osRes.readLine();
// Log.d("ProcessUtil", "s = " + s);
// res.add(s);
}
if (LOGD) {
Log.d(TAG, "Before exit");
}
os.writeBytes("exit\n");
os.flush();
if (LOGD) {
Log.d(TAG, "Before wait for");
}
process.waitFor();
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment