Burak Day Burak Day - 5 months ago 27
Android Question

How to kill or pause a process without killing its InputStream?

I want to start a

process inside the application by using:

Process get_event_process = Runtime.getRuntime().exec("getevent");

and get its output by using a

BufferedReader buffered_reader = new BufferedReader
(new InputStreamReader(get_event_process.getInputStream()));

String line = "";
log = new StringBuilder();
while((line = buffered_reader.readLine()) != null) {

The main problem is that the
process will never end unless it's killed. And if I kill the process I will lose my
with itself.

Is there a way to interrupt, pause the process, and get the produced input until that time?

Or is there a way to save the input of a never ending process like
sh -c getevent
even if I kill the process?


Ok so, I have found the solution with using ProcessBuilder instead of Process.

ProcessBuilder builder = new ProcessBuilder().command("getevent").redirectErrorStream(true);
Process get_event_process = builder.start();

Unfortunately it will stuck on while loop and give the output like this:

/dev/input/event5  Permission denied.
/dev/input/event4  Permission denied.
/dev/input/event3  Permission denied.
/dev/input/event2  Permission denied.
/dev/input/event1  Permission denied.
/dev/input/event0  Permission denied.

So with a rooted phone you can get the output by using:

chmod 666 /dev/input/*