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

Apps Calling command line from Native Library NDK

Discussion in 'Android Development' started by t.elimpus, Sep 15, 2011.

  1. t.elimpus

    t.elimpus Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Aug 12, 2011

    Aug 12, 2011
    6
    0
    5
    Hey Guys,
    I'm writing an app with a native library. Within, this library i need to use 'chmod' to allow permissions. It works fine when i type it into the terminal, but i have been trying to use this:

    system("chmod 777 /proc/bus/usb/001");

    but it doesn't work. I have tried lots of different syntax eg, ' // ' & ' \/' but it always fails. If anybody knows the correct way to call this, that would be fantastic!
    Thanks, Tony.
     

    Advertisement

  2. t.elimpus

    t.elimpus Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Aug 12, 2011

    Aug 12, 2011
    6
    0
    5
    Got it. The problem was, that before i was calling 'system("chmod....") i was calling 'system("su")' which i thought worked fine - becuase i got the pop up message.

    As 'su' is a shell, it was coming out of the shell before executing the 'chmod' line, and therefore restricting me from performing the 'chmod'. This is how i fixed it:

    Code (Text):
    1.  
    2. system("su -c \"chmod 777 /proc/bus/usb/001\"");
    3.  
    note:the backslashes are escape characters.
     

Share This Page

Loading...