Android root app echo not working with device driver

I am currently trying to write data to a HID driver that i have running on my phone. If i run the following command in shell (via adb) echo -e \\x00\\x00\\x07\\x04\\x00\\x00\\x00 > /dev/hidg0 && echo -e \\x00\\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0 the correct characters are typed on the computer connected to the device, which in this case is da. If however i send the same command in an android application like so

Runtime shell = Runtime.getRuntime();
Process p = shell.exec("su");
DataOutputStream out = new DataOutputStream(p.getOutputStream());
out.writeBytes("echo -e \\x00\\x00\\x07\\x04\\x00\\x00\\x00 > /dev/hidg0 && echo -e \\x00\\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0\n");

2 single quotes are printed but nothing else. I have proved that the app is getting root privilages by writing files to locations that can only be accesed by root.

So why would a command like this not act the same way in a shell as threw the process class? and does anyone have any suggestions as to how i should send data to my device driver?

Thanks Adrian

PS i have also tried shell.exec("echo -e \\x00\\x00\\x07\\x04\\x16\\x06\\x00 > /dev/hidg0 && echo -e \\x00\\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0"); but this gives me nothing


After Java processes the stream, the shell is seeing this command:

echo -e \x00\x00\x07\x04\x00\x00\x00...

i.e., Java is processing the double backslashes itself. You would need to add another set of escaped backslashes so that the shell actually sees a single escaped backslash. You could do

out.writeBytes("echo -e \\\\x00\\\\x00...")

but that looks horrible. Just pass a quoted string to the shell with

out.writeBytes("echo -e '\\x00\\x00\\x07\\x04\\x00\\x00\\x00' > /dev/hidg0 && echo -e '\\x00\\x00\\x00\\x00\\x00\\x00\\x00' > /dev/hidg0\n");

Need Your Help

What is the $scope – template designpattern called?

angularjs design-patterns handlebars.js

Is there a name for the front-end designpattern that is adopted by for example angular.js and to some degree Mustache/handlbars etc.

Grails addTo duplicates

grails groovy unique relationships jointable

I have the following association set up: