Skip to content Skip to sidebar Skip to footer

Problems With 'grep' Command From Adb

when i write in adb: adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' i get the error output: 'grep' is not recognized as an internal or external command, o

Solution 1:

There is no problem with grep in adb. There is a problem with your understanding of how shell works. So let's fix that:

In your adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' command only dumpsys window windows part runs on Android. Both adb shell and grep commands are being run on your Windows PC. Thus the error you get - you just don't have grep available.

When you run adb shell alone - you start an interactive adb shell session and everything you enter get executed on the Android side. This works great for manual testing. But adds an extra complexity layer when used for automation. To use the interactive mode from your code you would need multiple threads (one for the shell itself, another for sending the commands).

But in your case you do not really need all that complexity - just escape the "pipe" character or put the whole shell command in quotes like this:

adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"

Post a Comment for "Problems With 'grep' Command From Adb"