To gain the root permission of android, we usually do like this:
Process p=Runtime.getRuntime().exec(“su”);
DataOutputStream stream=new DataOutputStream(p.getOutputStream());
stream.writeBytes("mkdir /testFolder\n");
stream.writeBytes(“exit \n”);
p.waitFor();
Execute the codes above, we can create a folder /testFolder, everything is OK, but i feel confused about it. you know, when we want to execute some command in the terminal, we first input some codes, and the program read the input buffer to do something with the codes. But here we write string to the output stream of the sub-process, why? it seems that te sub-progress read command from its output buffer, not input buffer?
Maybe the naming is a little weird, but Process.getOutputStream() returns an
OutputStreamconnected to the standard input of the process.The names are from the point of view of the parent process. The parent process’s output is the subprocess’s input. The parent process’s input is the subprocess’s output.