gunes
gunes

Reputation: 131

how to use logcat commands within java code?

I want to use "adb logcat -d > C:\Users\lenovo 01\Documents\android\sdk\platform-tools" command line command within my java code. this works directly in command prompt but it doesn't work within java code. for example:

pb = new ProcessBuilder("adb", "logcat", "-d", ">", "C:\\android\\cellograf.txt");
pc = pb.start();
pc.waitFor();       
System.out.println("written");

when I execute this, nothing happens. It writes only "written" but the file is empty. When I run this command in command prompt, it works correctly and writes all logcat output to that file. What am I doing wrong?

Upvotes: 1

Views: 1100

Answers (1)

yole
yole

Reputation: 97133

Redirecting output to a file is a feature of the command interpeter; it's not something that can be performed by the process itself. Try appending cmd /c to the beginning of your command:

pb = new ProcessBuilder("cmd", "/c", "adb", "logcat", "-d", ">", "C:\\android\\cellograf.txt");

Upvotes: 1

Related Questions