Search code examples
androidbatch-fileterminaladblogcat

Stopping logcat using batch file


@for /f "delims=|" %%f in ('dir /b "C:\Users\User\Desktop\APKS\"*.apk') do (
adb install "C:\Users\User\Desktop\APKS\%%f"
adb logcat > "C:\Users\User\Desktop\Parser\LogsToParse\%%f.txt" 
)

So, right now I need to run a bunch of aps and log each of them. The problem is that the loop will run once and just stop to log the first app, but keep going for the rest of the ones after installing them as well.

Any idea how I'd terminate it? I know adb logcat -d works for just opening logcat and seeing whats going on for like a millisecond, but the problem is I need it open for 5 minutes and to be automated.

So far I've tried: Sending a null or bad request after X amount of time, sleeping, breaking, etc.

The only thing that seems to work is sending the terminal the CTRL+C command manually. Is there a way to do this manually after 5 minutes of logging using logcat?

Thanks.


Solution

  • After install apk, wait 5 minutes in batch,then use adb logcat -d.
    For "wait" in batch, you can use the timeout or ping command, like this:

    ping 1.1 -n 1 -w 3000>nul
    timeout /t 3
    

    Full script:

    @for /f "delims=|" %%f in ('dir /b "C:\Users\User\Desktop\APKS\"*.apk') do (
        adb logcat -c
        adb install "C:\Users\User\Desktop\APKS\%%f"
        timeout /t 300
        adb logcat -d > "C:\Users\User\Desktop\Parser\LogsToParse\%%f.txt" 
    )