1

I'm making a wrapper for a minecraft server console with Go. It uses os/exec to run the server and process.StdoutPipe() for realtime output from the subprocess.

But, I can't get it to display the colors for some reason. When I run the server directly from the terminal, colors work, but it doesn't work at all when I run it from Go.

What's more is there's no color codes on the log files either when I run it from Go. But running it directly from the terminal, the log file is absolutely messed up with color codes. I really don't get how that happens.

Is there any way to fix this?
Thanks!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
LollyPop Lolly
  • 135
  • 1
  • 1
  • 6
  • 1
    surely happens because minecraft detects the stdout is not a real console, so it strips the color, doing so you can redirect output to a file without the colors. Im not sure how you should proceed in go, there should be an option to define, or an env to set when invoking the minecraft program. –  Jul 15 '17 at 10:55

1 Answers1

4

The way to fix this is to force colors from the minecraft server. It's not a problem with your Go program at all. It's very common for command-line programs to detect whether they're running on an interactive terminal, and disable certain features (such as color output, paging, etc) when they are not, under the assumption that they're being passed through a script (as indeed it is, in your case).

If the minecraft server doesn't have this option, you may be able to fool it into thinking it's running on an interactive terminal.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Hi @Flimzy, thanks for the response. I tried to use `script` but for some reason it says `bash: 5: command not found`. That is when I run it from `exec.Command` of course ;P. But it works when I run it directly from the terminal tho. Any idea why this is happening? – LollyPop Lolly Jul 16 '17 at 12:33
  • 1
    Hiiii, actually I got it working!!! :D. Well I used what you said about fooling it into thinking it's running on an active terminal and I did some heavy research on fake tty. After hours I found this fantastic resource: [https://github.com/kr/pty](https://github.com/kr/pty) and every thing's working perfectly fine! Thanks again, couldn't have done it without you! – LollyPop Lolly Jul 16 '17 at 14:38