gpt4 book ai didi

java - Bash检测bash中的彩色文本输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:41 24 4
gpt4 key购买 nike

<分区>

我正在尝试检测我在 bash 脚本中运行的命令是否以特定颜色输出到终端。我的 Java 代码中有一些打印语句,根据输出内容以特定颜色输出。

这是使用以下代码完成的:

//ANSI color codes for output
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_RESET = "\u001B[0m";

System.out.println(ANSI_GREEN + "This prints in the color green." + ANSI_RESET);

有没有办法在 bash 中检测这种颜色差异?如果输出为红色,我希望能够停止 bash 脚本,或者如果它保持绿色则继续。如果有人知道这样做的方法,我们将不胜感激。

谢谢

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