你好,
使用最新的 phantomjs 1 9 7,我无法使用 console.err 写入 stderr。
在前端脚本中
throw "some errors";
在phantomjs脚本中
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onError = function(msg, trace) {
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
});
}
console.error(msgStack.join('\n'));
};
这有效
var phantomjsprocess = require('child_process').execFile(phantomjs.path, childArgs);
phantomjsprocess.stdout
.on('data', function (data) {
grunt.verbose.writeln(data.trim());
})
// having some difficuties to pass phantomjs errors to stderr, so listens to stdout for errors
.on('data', function (data) {
if( data.match(/^(ERROR: )/) ){
grunt.log.writeln(data.trim());
}
});
这没有,或者似乎没有。
var phantomjsprocess = require('child_process').execFile(phantomjs.path, childArgs);
phantomjsprocess.stderr
.on('data', function (data) {
grunt.log.writeln(data.trim());
});
我阅读了问题 #10232 这正是我的问题,但到目前为止,我无法让它工作。
你有什么提示吗?
谢谢。
哦,对不起,我错过了...感谢您的指点。
对于接下来的人,
将此代码段添加到 phantomjs 包装器中
console.error = function () {
require("system").stderr.write(Array.prototype.join.call(arguments, ' ') + '\n');
};
然后听听你的子进程的标准错误。
在phantomJS1.9上测试。 7@ubuntu13
奇迹般有效 !
@maboiteaspam我偷了你的代码片段并将它扔到https://github.com/sotownsend/BooJS中,默认情况下,console.error 上的 stderr。
最有用的评论
哦,对不起,我错过了...感谢您的指点。
对于接下来的人,
将此代码段添加到 phantomjs 包装器中
然后听听你的子进程的标准错误。
在phantomJS1.9上测试。 7@ubuntu13
奇迹般有效 !