gpt4 book ai didi

linux - 在不离开 bash 脚本的情况下中断 logcat?

转载 作者:太空宇宙 更新时间:2023-11-04 10:05:22 25 4
gpt4 key购买 nike

我写了一个基本的 shell 脚本,我打算用它来减少测试我的设备所需的时间。

我当前的问题是当我想停止执行 logcat 时,如果我使用标准的 Ctrl + C 命令,我会终止整个脚本。我只希望脚本循环回到选项菜单。

我确实需要 logcat 不断显示数据,所以 logcat -d 不是一个选项。

这个问题有解决办法吗?

谢谢。

代码如下:

#!/bin/bash

PS3='Select an option: '
options=("Restart ADB Server" "ABR Test" "Reboot the device" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Restart ADB Server")
printf "\nRestarting the ADB Server...\n"
adb disconnect
adb kill-server
adb start-server
adb connect 192.168.1.100
;;
"ABR Test")
printf "\nStarting the ABR Test\n"
clear
adb logcat | grep onVideoInputFormatChanged --line-buffered
;;
"Reboot the device")
printf "\nRebooting the device...\n"
adb reboot
;;
"Quit")
break
;;
*) printf "\n$REPLY is an invalid option!\n";;
esac
done

最佳答案

您可以尝试使用 SIGINT 捕获 Ctrl + C ( trap ) 生成的信号关键字 ( trap <callback> <signal> ) 并停止 logcat来自回调函数,像这样:

stop_logcat() {
# stop logcat here
}

trap 'stop_logcat' SIGINT

# your code here

有关 Traps 的文档.

关于linux - 在不离开 bash 脚本的情况下中断 logcat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52988719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com