某处[对象]被打印出来

时间:2015-03-02 00:59:39

标签: node.js stream gulp

我有几个gulp任务正在运行,完成后,当gulp即将退出时,[object Object]将被打印到控制台。

不知道这是从哪里来的。不知道这是一个gulp问题还是由模块引起的。

覆盖console.log没有用,因为[object Object]已经打印成字符串。

以下是Coffee中的gulp任务:

# Keep a reference so that we can kill it on process.exit
leinProcess = null

# Workaround to start the Clojure frontend server.
# This is needed when running E2E tests.
gulp.task('lein-run-static', (cb) ->

  leinProcess = spawn('lein', ['run-static'])

  # Here we compare each output until the line telling us that the frontend server is
  # up running, then we know it's ready.
  leinProcess.stdout.on('data', (data) ->

    line = data.toString().trim()

    # Do not print some duplicate lines
    if !line.match(/Requiring external|Running for version|Using gulpfile/)
      # Do not use gutil.log otherwise we see double dates
      console.log(line)

    if line.match(/Started SelectChannelConnector/)
      gutil.log('Frontend server started.')
      cb()
  )

  if config.debug
    leinProcess.stderr.pipe(process.stderr)

  # Make sure null is returned otherwise gulp will interpret leinProcess as
  # a gulp task stream
  return
)

我想在产生时使用stdio inherit但是我将失去解析stdout的能力。

你在这里建议什么?

1 个答案:

答案 0 :(得分:1)

继承除stdout以外的所有内容:

leinProcess = spawn('lein', ['run-static'], { stdio: [0, 'pipe', 2]})

http://nodejs.org/api/child_process.html#child_process_options_stdio

  

作为简写,stdio参数也可以是以下字符串之一:

     

'管' - [' pipe',' pipe',' pipe'],这是默认值

     

'忽略' - ['忽略','忽略','忽略']

     

'继承' - [process.stdin,process.stdout,process.stderr]或[0,1,2]