0

I'm trying to execute some commands from android app:

String[] cmd = {"su","-c","cat /storage/sdcard0/test.dat > /dev/ttyGS1"};
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();

Nothing happens after executing this but when I the same command works on adb shell without any problem.

su -c cat /storage/sdcard0/test.dat > /dev/ttyGS1

Does anyone know where I can try to find reason for this problem?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
seek
  • 1,065
  • 16
  • 33
  • Why do you need `su -c`? Just run `cat` as your current user... – OneCricketeer Mar 12 '17 at 22:08
  • I tried cat as current user but effect is the same. Nothing happens. I just read somewhere to try with su but also without any luck. Yes phone is rooted – seek Mar 12 '17 at 22:09
  • How about `{"cat", "/storage/sdcard0/test.dat > /dev/ttyGS1"}`? – OneCricketeer Mar 12 '17 at 22:09
  • Or, there is probably something about output redirection that can't be done from Java like that – OneCricketeer Mar 12 '17 at 22:10
  • @cricket_007 Because it's the shell (`sh`, `bash`, ...) that does pipe/redirect, not the OS, see duplicate link. Same for Windows (`cmd.exe`). – Andreas Mar 12 '17 at 22:11
  • @Andreas I understand that. There is "Nothing happens" in the Java code, sure – OneCricketeer Mar 12 '17 at 22:12
  • I read the duplicate link before asking this question but duplicate link says that "sh", "-c", "/storage/sdcard0/test.dat > /dev/ttyGS1" But it doesnt work also. – seek Mar 12 '17 at 22:14
  • @cricket_007 If output is not redirected to file, which it won't be without shell, then all output is sent to Java. If that output exceeds the buffer capacity, the `cat` command will stop to wait for buffer to be emptied, but Java program doesn't read output, so deadlock ensues. – Andreas Mar 12 '17 at 22:14
  • @Andreas Could you help how to make this pipe in my example. If I understand correctly I need to stream output from cat into serial port /dev/ttyGS1 but I have no idea how to make it happen. – seek Mar 12 '17 at 22:26

0 Answers0