Frage

So when running commands through an app, I've actually gotten the hang of it. But what's the point if you don't understand some of the characteristics. Right?

My question is what exactly does "-c" mean?

Runtime.getRuntime().exec(new String[]{"su","-c","reboot bootloader"});

Yes that line boots the device to the bootloader but I want to know, what does -c mean? I've tried searching but unrelated things are popping up.

War es hilfreich?

Lösung

Here are some hints how to find the answer.

The Java part

  1. Google for javadoc RunTime. It's usually the fastest way of getting the proper Oracle documentation.

  2. The first link is http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html, follow it.

  3. On the javadoc page, search for exec(String[] cmdarray). Follow the link (click on the exec name of the method).

  4. Read the javadoc:

    • Executes the specified command and arguments in a separate process.
    • Behaves in exactly the same way as the invocation exec(cmdarray, null, null)
    • Find the section describing the same method with three params (click on the exec name).
  5. Read the javadoc for the exec(String[], String[], File) method. While reading it, take into account that the last two parameters are null. You find that

Executes the specified command and arguments in a separate process... Given an array of strings cmdarray, representing the tokens of a command line... mdarray - array containing the command to call and its arguments

It means that your code

Runtime.getRuntime().exec(new String[]{"su","-c","reboot bootloader"});

does the same as if you run from your command line the command su giving it some arguments:

su -c 'reboot bootloader'

The Linux part

Use google and search for su command line arguments. Here you find that

su is usually the simplest and most convenient way to change the ownership of a login session to root or to any other user... Among the most commonly used of su's few options is -c, which tells su to execute the command that directly follows it on the same line.

So as you can see, your code calls the command reboot bootloader as a root.

Your own part

Next time, follow the above described procedure on your own :) I now invested a lot of time into you, do not waste it please :)

If you felt a slight sarcastic undertone in my answer, you are probably not far from the truth :) However please notice that it is not a pure RFTM answer, it really does answer your question and furthermore it teaches you how to find the answer on your own.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top