zoukankan      html  css  js  c++  java
  • 通过PowerShell查看Android端log信息

    在Windows下我们可以通过在cmd中输入adb logcat相关命令来查看安卓设备上的log信息,这在PowerShell里也可以做到。所以方便做成一个脚本,以便复用。代码如下:

    function List($target)
    {
        if($target.count -gt 1)
        {
            for($i=1;$i -le $target.count;$i++)
            {
                if(($target[$i] -ne "")-and($target[$i] -ne $null))
                {
                    "["+$i+"]"+$target[$i] | Write-Host -ForegroundColor Yellow   
                }
            }
        }else
        {
            "There are no devices, yet!" | Write-Host -ForegroundColor Yellow 
        }
    }
    Write-Host "---------Check-log----------" -ForegroundColor DarkMagenta
    $devices = adb devices
    Write-Host "Below are the devices attached:" -ForegroundColor Cyan
    List($devices)
    Write-Host "Choose the device number:" -ForegroundColor Green
    $choice = Read-Host
    $keyword = Read-Host "Type the keyword you want to find"
    adb -s ($devices[$choice].split())[0] logcat|Where-Object {$_ -like "*"+$keyword+"*"}

    将以上代码保存到一个ps1文件中,这里叫“logFilter.ps1”:

    右键使用PowerShell运行,效果如下:

    首先选择设备号,这里我只有一个设备。然后输入关键字,也就是keyword,我输入的是“crash”,之后就会列出来目标机器上所有包含“crash”字段的log信息。实时刷新。

  • 相关阅读:
    防御式编程
    Linux磁盘与文件系统管理
    更加抽象
    高质量的子程序
    Linux文件与目录管理
    抽象
    可以工作的类
    Linux的文件权限与目录配置
    条件、循环和其他语句
    软件构建中的设计
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/5360663.html
Copyright © 2011-2022 走看看