21

In the console I get "funky" output from Gradle when run from CMD since switching to Windows 10.

[0K
[0K
[2A[1m<==-----------> 18% EXECUTING [9s][m[34D[1B[1m> :compileScala[m[15D[1B[2A[1m<==-----------> 18% EXECUTING [10s][m[35D[2B[2A[1m<==-----------> 18% EXECUTING [11s][m[35D[2B[2A[1m<==-----------> 18% EXECUTING [12s][m[35D[2B[2A[1m<==-----------> 18% EXECUTING [13s][m[35D[2B[2A[1m<==-----------> 18% EXECUTING [14s][m[35D[2B[2Athere were four feature warnings; re-run with -feature for details
four warnings found

I imagine this is some sort of control-characters-gone-wild where Gradle is trying to sensibly colour its output and Windows is interpreting that wrong. PowerShell and SBT works fine - but copying the console "Properties" settings from PowerShell to CMD doesn't fixit.

Has anyone resolved this?

UPDATE 2018-01-28 It's also happening in my Jenkins/Alpine/Docker setup atop OSX/macOS/whatnot. Not just windows anymore.

... but ... it doesn't happen in the Surface laptop work gave me ... super weird. Whatevs gradlew --console=plain works fine for me.

pal
  • 942
  • 1
  • 9
  • 19
  • CMD restores the original console mode when running an external program, which is technically the right thing to do. Apparently PowerShell doesn't do this, so the virtual terminal escapes should work if you start CMD from PowerShell -- until someone fixes this bug in PowerShell. – Eryk Sun Jul 25 '17 at 17:34
  • The main bug here is in Gradle. If it depends on virtual terminal support, then it should enable it in the console by getting the current mode via `GetConsoleMode`, then OR in the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` flag, and set the new mode via `SetConsoleMode`. If this operation fails then VT mode isn't supported. It's either an older version of Windows or the option to use the legacy console is set. – Eryk Sun Jul 25 '17 at 17:40

6 Answers6

40

I've seen this happen in the Git BASH shell that's part of Git For Windows. For me, the solution was to set TERM to cygwin. This fixed the output without introducing any issues handling backspace.

export TERM=cygwin

I also tried xterm, xterm-256color, ansi, and vt100. The cygwin term has been the most reliable for me. I'm now running \usr\bin\bash.exe in Windows Terminal, and so far it has worked well.

Mark McClelland
  • 4,980
  • 4
  • 35
  • 48
  • That seems to work, though I don't get the logic of why a Windows Terminal environment needs a cygwin TERM. I guess one of the mysteries of cygwin kruft. – xpusostomos Oct 13 '20 at 10:05
  • 9
    if you use git bash in windows. edit the file in git\etc\bash.bashrc and add the line export TERM=cygwin to the end of the file so you don't have to type this command everytime you run a terminal – Ali Nov 15 '20 at 04:38
  • 1
    @Ali suggestion above worked for me when I added it to the .bash_profile file in my windows home directory. – Grant Lay Jan 14 '21 at 00:48
  • @xpusostomos it's probably trying to do this: https://en.wikipedia.org/wiki/ANSI_escape_code – Ray Tayek May 20 '21 at 21:02
  • You can put this export statement in the `bash.bashrc` in the `Git/etc` installation folder Mine was: `C:\Program Files\Git\etc\bash.bashrc` – ThangLeQuoc Oct 29 '22 at 10:18
12

I'm guessing you could pass --console plain in the gradle command line to disable the rich console which is likely the cause of the "funky" characters

https://docs.gradle.org/current/userguide/gradle_command_line.html

lance-java
  • 25,497
  • 4
  • 59
  • 101
  • Gradle 2.6 in powershell under win 10 produces correct behavior but gradle 4.1 does not. – Καrτhικ Dec 15 '17 at 19:33
  • Yes, there's similar weirdness when I run Gradle through git bash on Windows. Gradle works fine in normal DOS terminal on Windows. As I said you can use `--console plain` to stop the special characters – lance-java Dec 15 '17 at 19:46
  • it seems to work. output are much better but I won't be able to see the percentage % using the export TERM=cygwin like Mark mentioned below seems to give a better results – Ali Nov 15 '20 at 04:40
1

To fix this on Windows 10 create a new DWORD key HKEY_CURRENT_USER\Console\VirtualTerminalLevel set to 1. See this for more info.

Jerry
  • 1,127
  • 2
  • 17
  • 35
1

I get the same problem when using Windows Terminal and "Git Bash" profile added automatically by GIT installer. For me the solution was to change the command-line for starting the terminal from <git_install_path>/bin/bash.exe to <git_install_path>/bin/usr/bash.exe following this advice.

jannis
  • 4,843
  • 1
  • 23
  • 53
0

like @lance-java said the ANSI output can be disabled throw the command line option --console

./gradle bootRun --console plain 

or

./gradle bootRun --console=plain

another way is to set the property in the gradle.properties file

org.gradle.console=plain 

see documentation: Gradle configuration properties

velocity
  • 1,630
  • 21
  • 24
-1

The solution for me was to just update Git Bash: git update-git-for-windows

Anonsage
  • 8,030
  • 5
  • 48
  • 51