Created
August 26, 2010 21:11
-
-
Save CedricGatay/552267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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