Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:41:04+00:00 2026-05-27T03:41:04+00:00

I have a small script that colorizes compiler(maven) output so errors won’t be overlooked

  • 0

I have a small script that colorizes compiler(maven) output so errors won’t be overlooked anymore.

#!/bin/sh
export TEXT_YELLOW=`tput setaf 3`
export TEXT_RED=`tput setaf 1`
export RESET_FORMATTING=`tput sgr0`

mvn $* | sed \
-e "s/\(\[WARNING\].*\)/${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
-e "s/\(\[ERROR\].*\)/${TEXT_RED}\1${RESET_FORMATTING}/g"

Problem is the shell within a shell feature my compiler has (mvn cli:execute-phase). There a command prompt like maven2> should be visible on screen and the user is then able to type in commands. Unfortunately due to my script I see nothing but a blinking cursor. Only when I press the enter key the maven2> prompt-prefix-text pops up.

My guess is that sed is waiting for an EOL before it prints something on screen. To fix it I would have to look if the stream starts with the string maven2>. If it does then print out directly to terminal, otherwise forward it to sed. Is it possible in bash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:41:05+00:00Added an answer on May 27, 2026 at 3:41 am

    Okay, I found a solution. I tried a lot of things but was unable to solve the problem purely with bash in the end. So I wrote a python script instead and it works. Just pipe the maven output to the script like mvn cli:execute-phase | colorize.py. It is also possible to write an alias in your bashrc so all maven calls have colorized output.

    #!/usr/bin/python
    # Same as regular mvn command but with colored output.
    
    import sys, subprocess, os, time
    
    def colorize( line ):
        red = '\033[1;31m'
        yellow = '\033[1;33m'
        endcolor = '\033[1;m'
    
        if ("[ERROR]" in line) or ("ERROR" in line ) or ( "Failures" in line ) or ( "Errors" in line ):        
            print red + line + endcolor,    
        elif ("[WARNING]" in line) or ( "WARN" in line ):
            print yellow + line + endcolor,
        else:
            print line,
    
    
    line=""
    printPrompt = True
    while True:
    
        c = sys.stdin.read(1)
    
        if not c:
            # eof
            break
    
        line = line + c
    
        if printPrompt:
            if line.startswith("maven2>"):        
                print "maven2>",
                sys.stdout.flush()
                printPrompt = False
        else:
            # rewrite the current line to console
            sys.stdout.write('\r')
            print line,
            sys.stdout.flush()
    
        if c.endswith("\n"):
            colorize(line)
            line = ""
            printPrompt = True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small script that I am try to port to work for
I have a small cgi script that fetches and validates a configuration file for
I have a script that animates a small DIV popping up on the page.
I have a small script that checks a large list of domains for their
I have this small script that sorts the content of a text file #
I have a problem with my index.php, i have this small script that decides
I have small HTTP server script that receives HTTP client requests and replies. I
I have a small python cgi script that accepts an image upload from the
I have this small script that shows a caption for a img when it
I have a small script that moves the frame head backwards and forwards depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.