1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

    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.

    1. Download the Forums for Android™ app!


  2. t.elimpus

    t.elimpus Lurker
    Thread Starter

    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):
    2. system("su -c \"chmod 777 /proc/bus/usb/001\"");
    note:the backslashes are escape characters.

Share This Page