Need to capture adb logs and push output to file using java

Hi All,

Currently i am using TestNG framework.

1 Need to capture the adb logs and write it some file.
2. validate the Tags present or not in the output file using Shell script.

Plz help to resolve it

Thanks & Regards
Shashi Kumar JB

Check this out to get adb log:

		String filter = "adb logcat -d <filterName>:V *:S";
		Process p = Runtime.getRuntime().exec(

After this save it to file and validate through java code whether particular tags are present or not

If you are after logcat, appium gives you a mechanism for grabbing them. It’s not very flexible; we just grab all of them. Here’s an example in Ruby. I’ll have to hope you get the general idea and can translate it into Java


1 Like
	public void launchAVD() throws InterruptedException, IOException {
		ProcessBuilder pbEmulator = new ProcessBuilder("emulator", "-avd", "EmulatorAndroidName");
		Process pcEmulator = pbEmulator.start();
		ProcessBuilder pbADB = new ProcessBuilder("adb", "devices");
		Process pcADB = pbADB.start();
		InputStream is = pcADB.getInputStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		String line;
		String adb = new String();
		while ((line = br.readLine()) != null) {
		    if (line.length()>0)
			line += br.readLine();
		if (adb.contains("emulator-5554") && (!adb.contains("offline"))) {
			System.out.println("Device is connected");	

Hi Amit,

Using above code I m not able to capture the logs…

Please help to capture the ADB logs and write to file