0

I made some buttons in my app that exec a bash cmd.

Here is my string:

    final String[] test = {"su","-c","echo test > /system/test.txt"};

This cmd works, in fact, i can see the test.txt file on /system/ with the line test inside.

My question is: When i push on the button for exec that cmd the device create a toast with the string "echo test /system/text.txt". I'm guessing this is due to "-c", anyway:

    final String[] test = {"su","echo test > /system/test.txt"};

won't work, and:

    final String[] test = {"su","-c","echo test > /system/test.txt >> /dev/null"};

won't work as well and create a toast showing "echo test /system/test.txt /dev/null"

is there any way i can avoid this "problem"?

Also, can anyone show me a little function that create a toast with a spinning wheel when i onClick to the button that exec it?

Thanks!!!

iGio90
  • 290
  • 1
  • 4
  • 15
  • This is probably a side effect of the su hack on your particular phone, intended to give the user the vaguest idea of how apps are using it. And incidentally, you are executing a shell command, but that shell is probably not bash, but rather toolbox or possibly busybox. – Chris Stratton Jan 25 '13 at 13:30
  • To clarify, /dev/null is not the answer, as neither stdout nor stderr is involved in the creation of the Toast. It is very intentional that this user security notification *not* be something which can be hidden. – Chris Stratton Jul 02 '13 at 11:27

1 Answers1

-1

This extract from su manual should clear your question about -c option:

-c, --command=COMMAND pass a single COMMAND to the shell with -c

And

final String[] test = {"su","-c","echo test > /system/test.txt >> /dev/null"}; 

won't work because Android don't have /dev/null device. To get it work you need to have a -c option after su and get a rid of /dev/null. You may use android API to delete this file instead.

XorOrNor
  • 8,868
  • 12
  • 48
  • 81
  • Hello, the command itself works well! i don't need to delete the file! i need to remove the toast that appears when i click on the button that exec the command!!! – iGio90 Jan 25 '13 at 11:34
  • I don't get it. Why did you created this toast if you don't wanna display your results there? – XorOrNor Jan 25 '13 at 11:45
  • the "toast" appear itself whwnever you execute a bash "su -c cmd" command: an example is when you execute an app with root permission already granted... once you open it and it exec "su" a toast message appear saying "this app has now root access" ... in my case appear "this app as now root access echo test > etc " – iGio90 Jan 25 '13 at 11:52
  • 1
    Untrue, android does have a /dev/null – Chris Stratton Jan 25 '13 at 13:28
  • @Chris Stratton - You're wrong the Android OS do have the `/dev/null` device but you have to have a rooted device to see it. Without root permissions you can't go lower than `/storage` (down to `/`). – XorOrNor Jul 02 '13 at 07:37
  • Ah, no, that would *not* be true. Only specific areas are restricted, and they vary by version. /dev/null is also utterly unrelated to the question asked, since the Toast has nothing to do with stdout or stderr. – Chris Stratton Jul 02 '13 at 11:18