I was trying to run the following instruction,
Process p = Runtime.getRuntime().exec("/system/bin/lsof|grep mediaserver");
In android(java) but I am getting error. if I run following instruction,
Process p = Runtime.getRuntime().exec("/system/bin/lsof ");
the file is successfully saved.Can anyone tell what is the error? Actually I want to list and check if media server service is being running or not.
The grep utility may not be installed on your device.
You can check it by trying the following in a console:
The last line indicates that this command is not available.
The problem is that
Runtime.getRuntime().exec(...)
does not know how to deal with the shell language. On a Linux / Unix platform you would so something like this:However, (apparently) Android doesn't have a command shell / command prompt by default. So either you need to identify and install a suitable shell on your device, or construct the pipeline "by hand"; i.e. by creating a "pipe" file descriptor, and execing the two commands so that
lsof
writes to the pipe andgrep
reads from it.Maybe the answer is to run it like this ...
(Try running the "shell ...." part from adb interactively before doing it from Java.)