【发布时间】:2015-03-02 00:59:39
【问题描述】:
我有几个 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,但之后我将失去解析标准输出的能力。
你有什么建议?
【问题讨论】:
-
这就是coffeescript如此出色的原因,它让调试变得非常容易
-
我疯狂地猜测
data是一个对象,在它上面调用toString会给你[object Object] -
顺便问一下问题是什么?消息来自哪里或如何设置 stdio? :)
-
是和不是。我想通了。数据已经在代码的其他地方转换为字符串。因此,在字符串“[object Object]”上调用
toString()将再次返回[object Object]。很简单。 -
@Heikki stdio 在类似的 GitHub 问题上被提及,这让我在这里问了同样的问题。