0

I want to execute the "adb logcat -d time > pathoffile\log.txt &" in my java code.

I want to create my log.txt in my device.

I wrote this code to do this.

 ArrayList<String> commandLine = new ArrayList<String>();
        commandLine.add("logcat");
        commandLine.add("-d");
        commandLine.add("time");
        commandLine.add(">");
        commandLine.add(getApplicationContext().getFilesDir()
        //      + "/log.txt");   //already created the file at specified location.
        //commandLine.add("&");
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));

The above code not throwing any error , but my file (log.txt) is not updating with the log statements..

please help me in this how to do this, pl. suggest if there's any alternative to do this.. thanks.

brig
  • 305
  • 2
  • 6
  • 12
  • How did you create the file? Perhaps it is a permission problem? – Mark Jun 29 '11 at 08:23
  • I created file like this: File logf= new File(getApplicationContext().getFilesDir() + "/log.txt"); logf.createNewFile(); and I can see the log.txt file by navigating to that files directory. So I think its not a permission problem. If its it will throw IO Exception. – brig Jun 29 '11 at 08:38

1 Answers1

4

Try -f option instead:

adb logcat -d time -f /mnt/sdcard/log.txt

Note that > is io redirection feature of shell. It has no effect when used with exec() function.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • Thanks inazaruk, its working now, we need to add READ_LOGS permission to the manifest file also. – brig Jun 29 '11 at 10:38