I want to execute some Unix commands from the java code.
I want to run logcat command from java code.
I am using the below code to do this:
Process p = Runtime.getRuntime().exec("logcat -v time -f /mnt/sdcard/abc.txt");
The above code is working perfectly.
The same way I want to run some other Unix commands .
I want to run "WC -l"(read no.of lines in file) command and I want to store it out put in some integer.
Below is the code that I have written for this:
Process p = Runtime.getRuntime().exec("wc -l /mnt/sdcard/abc.txt");
But it is throwing below exception.
08-19 05:34:53.457 W/System.err( 1269): java.io.IOException: Error running exec(). Command: [wc, -l, /mnt/sdcard/abc.txt] Working Directory: null Environment: null
08-19 05:34:53.457 W/System.err( 1269): at java.lang.ProcessManager.exec(ProcessManager.java:224)
08-19 05:34:53.457 W/System.err( 1269): at java.lang.Runtime.exec(Runtime.java:189)
08-19 05:34:53.457 W/System.err( 1269): at java.lang.Runtime.exec(Runtime.java:275)
08-19 05:34:53.457 W/System.err( 1269): at java.lang.Runtime.exec(Runtime.java:210)
Please help me what's the issue in this..
I have a file "abc.txt" in SD card.
is it possible to execute "WC -l" command from java code of android.
If we can execute Unix commands from java code we can make file operations very easier.