docker - `dotnet test` 捕获弄乱输出的垃圾字符 - 需要删除
问题描述
我期待脚本捕获垃圾字符的类似问题 - 需要删除. 日志和控制台输出包含这些 ANSI 转义序列并与结果输出混淆。很难理解实际过程中发生了什么。我们正在使用 Centos:7 并且dotnet test
在 docker 容器中运行。我们正在构建和测试 dotnet 应用程序。所有日志都是可见且完美的,但在dotnet test
命令期间我们收到多个垃圾字符,它也弄乱了结果。看起来这些字符还包含使日志从终端开始开始而不清除旧日志的内容,并且还会弄乱日志。
输出
Run test [sample_test]
Test Run Successful.ding projects
Total tests: 1
Passed: 1
Total time: 1.9039 Seconds
Installing trx2junit
You can invoke the tool using the following command: trx2junit
Tool 'trx2junit' (version '1.2.6') was successfully installed.
trx2junit (c) gfoidl -- v1.2.6sion 16.3.0+0f4c62fea for .NET Core
https://github.com/gfoidl/trx2junit. All rights reserved.
....
...
./build/xunit-results/sss.Test.trx
./build/xunit-results/junit-results/sss.Test.xml
~/testError(s)
Test done!ed 00:00:05.11
zzz:~/git/testproject$ ;1R;9R;1R;9R;1R;9R
........
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: /tmp/tmp.Lr3H7XaRyB/build/xunit-results/sss.Test.trx
^[[40;1R^[[40;9R
使用or选项dotnet test
在 docker 容器中运行时会遇到此问题。如果我们在带有选项的 docker 容器中运行相同的操作,它可以完美地工作,没有任何不需要的字符。--tty
-t
dotnet test
-it
dotnet test
我认为在 docker 容器中与--tty
选项的组合存在一些问题。
任何帮助和建议将不胜感激。
解决方案
我为这个问题找到的解决方案是将输出通过管道tr
传输到剥离控制字符:
# Strip control characters from output except `\t\n\r`.
dotnet test | tr -d '\000-\010\013\014\016-\037'
复制自此 SO 评论:Removing Control Characters from a File。该线程有许多其他解决同一问题的方法。
推荐阅读
- windows - 使用 FTP 从目录中获取名称包含特定字符串的特定文件
- rest - 如何创建用于触发进程的 Rest Api
- laravel-5 - 我的应用程序中无法使用外部 API 和内部请求验证令牌签名
- jquery - 随机单击时跨度崩溃不起作用
- javascript - 如何在不手动设置时间延迟的情况下同步执行java脚本行
- laravel - 查看 [relations.one-two-many.category.index] 未找到。: 拉拉维尔
- linux - 编写shell脚本将目录中最旧的文件移动到新目录。?
- kubernetes - 创建部署与运行部署
- mysql - 使用 MySQL 创建表时出现 ERROR 1064
- java - 无法理解从 Int 到 Char 的 Java 有损对话