通过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信息。实时刷新。

posted @ 2016-04-06 19:05  天外归云  阅读(686)  评论(0编辑  收藏  举报