代码之家  ›  专栏  ›  技术社区  ›  Amit Wagner

在控制台中启动stdout数据之前,是否有方法更改所有stdout数据?

  •  1
  • Amit Wagner  · 技术社区  · 6 年前

    因为sdtout是我尝试做的一条小溪

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

    有什么建议吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Terry Lennox    6 年前

    看一看 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");