【问题标题】:Not getting desired output in electron app but getting the same in node CLI using same Nodejs file没有在电子应用程序中获得所需的输出,但在使用相同的 Nodejs 文件的节点 CLI 中获得相同的输出
【发布时间】:2017-05-18 06:52:29
【问题描述】:

我正在尝试在我的电子应用程序中显示 docker 容器日志。我正在使用 dockerode API。我在 dockerode 中找不到命令,所以我使用 node-cmd 在 CLI 中执行并获取输出。但它仅在 NodeJs 命令行中有效,但在电子中同样带有额外的字符,如图像。任何帮助将不胜感激。

节点js文件:

var Docker = require('dockerode')
var docker = new Docker({ host:'127.0.0.1',port:2375});
//festive_jepsen is container name.
//using alert for electron and console for nodejs CLI

var cnt='festive_jepsen';
var cmd=require('node-cmd');
function onl()
{
    cmd.get(
        'docker logs '+cnt,
        function(err, data, stderr){
            alert(data);
            //console.log(data);
        }
    );
}

This is the input i want and it is executing perfectly in nodejs CLI

This is how the output is in Electron app if i use the same code and alert box instead of console.log

【问题讨论】:

  • 那些看起来像 ANSI 颜色代码。控制台正在使用它们来更改文本颜色,但警告对话框不知道如何处理它们。
  • @takteek 或者ANSI空格,因为白线里面也有不同的代码...

标签: node.js electron


【解决方案1】:

我使用 ansi-to-html API 来转换彩色文本。 现在完美运行。

节点js文件:

var Convert = require('ansi-to-html'); var convert = new Convert(); Converted_data = convert.toHtml(data); //data is the string with colored text

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 2016-06-19
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多