【问题标题】:Is there a way to change all stdout data before it fired in the console?有没有办法在控制台触发之前更改所有标准输出数据?
【发布时间】:2018-09-21 07:59:50
【问题描述】:

我需要处理发送到 stdout 的所有数据。 因为 sdtout 是我尝试做的一个流

process.stdout.on('data', chunk => {
  //change chunk and return it
});

但这并没有做任何事情。

有什么建议吗?

【问题讨论】:

    标签: javascript node.js console stdout


    【解决方案1】:

    看看https://www.npmjs.com/package/intercept-stdout

    您可以使用此模块连接到标准输出:

    var intercept = require("intercept-stdout");
    
    var unhook_intercept = intercept(function(txt) {
        return txt.replace( /this/i , 'that' );
    });
    
    console.log("This text is being modified");
    
    // Stop intercepting stdout
    unhook_intercept();
    
    console.log("This text is _not_ being modified");
    

    【讨论】:

      猜你喜欢
      • 2013-05-21
      • 2014-05-23
      • 1970-01-01
      • 2012-05-13
      • 2015-05-14
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多