problems with 'grep' command from adb

后端 未结 1 1001
予麋鹿
予麋鹿 2020-12-11 04:21

when i write in adb:

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

i get the error output:

\'gr         


        
相关标签:
1条回答
  • 2020-12-11 05:04

    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'"
    
    0 讨论(0)
提交回复
热议问题