【问题标题】:Grunt spawned process not capturing outputGrunt 产生的进程没有捕获输出
【发布时间】:2013-02-09 06:12:54
【问题描述】:

我已经使用 Grunt 生成了一个进程,但是控制台中没有显示任何写入输出流的内容(例如 console.log)。

我希望 Grunt 显示进程的任何输出。

grunt.util.spawn(
  { cmd: 'node'
  , args: ['app.js']
  , opts:
      { stdio:
          [ process.stdin
          , process.stout
          , process.stderr
          ]
      }
  })

【问题讨论】:

    标签: node.js process gruntjs spawn


    【解决方案1】:

    尝试将其设置为opts: {stdio: 'inherit'}。否则,您可以通过管道输出:

    var child = grunt.util.spawn({
      cmd: process.argv[0], // <- A better way to find the node binary
      args: ['app.js']
    });
    child.stdout.pipe(process.stdout);
    child.stderr.pipe(process.stderr);
    

    或者如果你想修改输出:

    child.stdout.on('data', function(buf) {
        console.log(String(buf));
    });
    

    【讨论】:

    • stdio: 'inherit' 成功了,感谢您提供找到 Node 二进制文件的提示!
    猜你喜欢
    • 1970-01-01
    • 2020-10-18
    • 2019-06-10
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    相关资源
    最近更新 更多