public static Process doShellCommand(Java.Lang.Process proc, string[] cmds, FFMpegCallbacks sc, bool runAsRoot, bool waitFor) { var r = Runtime.GetRuntime(); if (proc == null) { if (runAsRoot) { proc = r.Exec("su"); } else { proc = r.Exec("sh"); } } OutputStreamWriter outputStream = new OutputStreamWriter(proc.OutputStream); for (int i = 0; i < cmds.Length; i++) { logMessage("executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor); outputStream.Write(cmds[i]); outputStream.Write("\n"); } outputStream.Flush(); outputStream.Write("exit\n"); outputStream.Flush(); if (waitFor) { char[] buf = new char[20]; // Consume the "stdout" InputStreamReader reader = new InputStreamReader(proc.InputStream); int read = 0; while ((read = reader.Read(buf)) != -1) { if (sc != null) { sc.ShellOut(new string(buf)); } } // Consume the "stderr" reader = new InputStreamReader(proc.ErrorStream); read = 0; while ((read = reader.Read(buf)) != -1) { if (sc != null) { sc.ShellOut(new string(buf)); } } proc.WaitFor(); } sc.ProcessComplete(proc.ExitValue()); return(proc); }
public static int doShellCommand(string[] cmds, FFMpegCallbacks sc, bool runAsRoot, bool waitFor) { return(doShellCommand(null, cmds, sc, runAsRoot, waitFor).ExitValue()); }