在 Android 应用程序 运行 时使用批处理文件在 PC 上获取 adb 日志
Getting adb logs on PC using a batch file while the Android app is running
我创建了一个 windows 批处理文件 (log.bat),如下所示:
adb logcat -c
adb logcat -d > log.txt
但是只要我按log.bat命令,它很快就会退出。
我希望它一直记录日志,除非我按 ctrl+C。
我需要创建一个可以将日志文件复制到 PC 的批处理文件。我创建的批处理文件不起作用。当我 运行 手动执行所有命令时,它可以正常工作,但是当放入脚本时它会挂起。以下是单独的命令:
试试这个单行命令:
$adb shell run-as com.example.name cat /data/data/com.example.name/files/logfile.log > c:\logs\logfile.log
看起来问题出在将选项 -d 与 logcat 一起使用。请检查使用情况:
-d 转储日志然后退出(不要阻塞)
删除它将解决您的问题。
来自doc
-c : Clears (flushes) the entire log and exits.
-d : Dumps the log to the screen and exits.
因此,在这两种情况下,一旦您使用这些选项 运行 logcat 命令,执行就会停止。试试这个,
adb logcat -c && adb logcat > log.txt
这不会让 shell 执行一旦执行 logcat -c
就会被释放,并且会在它之后立即启动下一个命令,即 adb logcat > log.txt
将要写入logcat 的日志,直到您按下 Ctrl + c。
我创建了一个 windows 批处理文件 (log.bat),如下所示:
adb logcat -c
adb logcat -d > log.txt
但是只要我按log.bat命令,它很快就会退出。
我希望它一直记录日志,除非我按 ctrl+C。
我需要创建一个可以将日志文件复制到 PC 的批处理文件。我创建的批处理文件不起作用。当我 运行 手动执行所有命令时,它可以正常工作,但是当放入脚本时它会挂起。以下是单独的命令:
试试这个单行命令:
$adb shell run-as com.example.name cat /data/data/com.example.name/files/logfile.log > c:\logs\logfile.log
看起来问题出在将选项 -d 与 logcat 一起使用。请检查使用情况:
-d 转储日志然后退出(不要阻塞)
删除它将解决您的问题。
来自doc
-c : Clears (flushes) the entire log and exits.
-d : Dumps the log to the screen and exits.
因此,在这两种情况下,一旦您使用这些选项 运行 logcat 命令,执行就会停止。试试这个,
adb logcat -c && adb logcat > log.txt
这不会让 shell 执行一旦执行 logcat -c
就会被释放,并且会在它之后立即启动下一个命令,即 adb logcat > log.txt
将要写入logcat 的日志,直到您按下 Ctrl + c。