1. Download our Official Android App: Forums for Android!

Apps How to execute shell commands in android app?

Discussion in 'Android Development' started by kbn456, Apr 2, 2013.

  1. kbn456

    kbn456 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 1, 2013

    Apr 1, 2013
    1
    0
    5
    Hi All,

    I'm new to android app's.
    I need to execute following command in my app.
    command: echo "1" > /sys/manager0/enable

    I tried this with following code in my app.

    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
    String cmd = "echo \"1\" /sys/manager0/enable";
    stdin.writeBytes(cmd+"\n");

    There is no error and app executed perfectly but there is no change in the /sys/manager0/enable

    Please give suggest some solution to this.

    Thanks in advance.
     

    Advertisement

  2. GeorgeN

    GeorgeN Well-Known Member
    Rank:
    None
    Points:
    73
    Posts:
    132
    Joined:
    Apr 16, 2012

    Apr 16, 2012
    132
    38
    73
    Male
    London
    It looks like you are missing a ">" character in your command. The command yo are executing will just print "1 /sys/manager0/enable" to stdout.
     
  3. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    Also, in order to successfully execute "su", you need to ensure that the device has root access.
     

Share This Page

Loading...