2

I have rooted my device, then in my application

Process p = Runtime.getRuntime().exec("su");

and it work fine, my application will be root mode. Then I try add wlan address space, but it doesn't work, when I check out in terminal, following error message is shown

 busybox ifconfig there is not a new wlan address space. 

I try with following way:

Process p = Runtime.getRuntime().exec("su");
p = Runtime.getRuntime().exec("busybox ifconfig wlan0 add xxxxxxxxxxxx");
p.waitfor();

When I run my application, the toast shows that the app is root mode but there is not added wlan0.

1
  • Of course, if I write in terminal su, busybox ifconfig wlan0 add xxxxxxxx, it's works fine and there is a new wlan0 address space. Commented Aug 2, 2011 at 6:51

3 Answers 3

1

The "su -c COMMAND" syntax is not really supported. For better portability, use something like this:

p = Runtime.getRuntime().exec("su");
stream = p.getOutputStream();
stream.write("busybox ifconfig wlan0 add xxxxxxxxxxxx");

The write() command doesn't exists as-is, but I'm sure you'll find how to write your stream to it, maybe encapsulating the output stream in a BufferedOutputWriter or so.

Sign up to request clarification or add additional context in comments.

Comments

1

because the process that started with "busybox" is not the same one which started with "su". you should like this:

Process process = Runtime.getRuntime().exec("su");
OutputStream os = process.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
dos.writeBytes("busybox ifconfig wlan0 add xxxxxxxxxxxx" + "\n");
dos.flush();

Comments

0

That might be because when you run su, it launches one process. Then you run busybox ..., and it happens in another process, which is not started as a superuser.

Try something like

Process p = Runtime.getRuntime().exec(new String[] {"su", "-c", "busybox ifconfig wlan0 add xxxxxxxxxxxx"});

, i.e. executing it in a single command-line.

8 Comments

sorry, It dosen't works! no more toast that app is superuser and no wlan address space added.
@user760503: oh sorry, i forgot the -c switch. It should look like this: exec("su -c \"busybox ifconfig wlan0 add xxxxxxxxxxxx\"")
@user760503: man su tells that the syntax is su -c COMMAND.
yes,I noticed after reading man pages. but it doen't work. I have tried out following way:
exec("su -c \"busybox ifconfig wlan0 add xxxxxxxxxxxx\"") dosen't work and and following works only sudo part: String[] cmd = {"su","-c","busybox","ifconfig wlan0 add xxxxx"} sudo works now but no wlan has been added!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.