brig
brig

Reputation: 315

how to execute "adb logcat -d time > pathoffile\log.txt &" programatically

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.

Upvotes: 0

Views: 5253

Answers (1)

inazaruk
inazaruk

Reputation: 74790

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.

Upvotes: 4

Related Questions