GoLang OS/exec StdoutPipe颜色 [英] GoLang os/exec StdoutPipe with colors

查看:76
本文介绍了GoLang OS/exec StdoutPipe颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GoLang为 minecraft 服务器控制台包装.它使用os/exec来运行服务器和进程.StdoutPipe()用于从子进程实时输出.

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

但是,由于某种原因,我无法显示颜色.当我直接从终端运行服务器时,颜色可以工作,但是当我从GoLang运行服务器时,它根本无法工作.

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 GoLang.

此外,当我从GoLang运行该文件时,日志文件上也没有颜色代码.但是直接从终端运行它,日志文件绝对被颜色代码弄乱了.我真的不知道怎么回事.

What's more is there's no color codes on the log files either when I run it from GoLang. 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!

推荐答案

解决此问题的方法是从Minecraft服务器中强制使用颜色.Go程序根本不是问题.命令行程序通常会检测它们是否在交互式终端上运行,并在不使用某些功能(例如颜色输出,页面调度等)的情况下禁用它们,这是假定它们正在通过脚本(实际上就是您的情况).

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).

如果Minecraft服务器没有此选项,则可以使其误以为它正在交互式终端上运行.

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.

这篇关于GoLang OS/exec StdoutPipe颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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