• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Calling command line from Native Library NDK

t.elimpus

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