根据bash中的输出退出正在运行的命令 [英] Quit a running command based on output in bash

查看:44
本文介绍了根据bash中的输出退出正在运行的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开始使用的进程

I have a process which I start running using

$ somecommand构建

它基本上是在Android模拟器上安装应用程序,然后启动模拟器.这个过程一直持续到我手动将其杀死为止.

It basically installs an app on an Android emulator and then starts up the emulator. This process keeps running forever until i manually kill it.

此命令在运行应用程序时也会向终端输出一堆调试信息.我想在此连续输出中的某处在终端上输出字符串 [TESTS_ENDED] 时终止该命令.

This command outputs a bunch of debug info into the terminal, also while running the app. I'd like to kill the command when somewhere in this continuous output, the string [TESTS_ENDED] has been outputted on the terminal.

有任何关于如何做到这一点的人吗?

Any oneliner on how to do this?

推荐答案

pkill 的帮助下,使用 awk :

somecommand build | awk '/\[TESTS_ENDED\]/ {system("pkill somecommand")}'

  • 假设正在运行 somecommand 的一个实例

    \ [TESTS_ENDED \] 与该行中的 [TESTS_ENDED] 匹配

    如果匹配,将运行 {system("pkill somecommand")} ,即 awk 将使用 system()函数运行 pkill somecommand ,即 somecommand 将被 pkill

    If matched, {system("pkill somecommand")} will be run i.e. awk will use system() function to run pkill somecommand i.e. somecommand will be killed by pkill

    这篇关于根据bash中的输出退出正在运行的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆