Phantomjs: console.errorはstderrに書き込みますか?

作成日 2014年02月08日  ·  3コメント  ·  ソース: ariya/phantomjs

こんにちは、

最新のphantomjs1 9 7を使用すると、console.errを使用してstderrに書き込むことができません。

フロントエンドスクリプトで

  throw "some errors";

thephantomjsスクリプトで

  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

チャームのように機能します!

全てのコメント3件

申し訳ありませんが、私はそれを逃しました...指摘してくれてありがとう。

次の人のために、
このスニペットをphantomjsラッパーに追加します

console.error = function () {
    require("system").stderr.write(Array.prototype.join.call(arguments, ' ') + '\n');
};

次に、子プロセスの標準に耳を傾けます。

phantomJS1.9でテスト済み。 7 @ ubuntu13

チャームのように機能します!

@maboiteaspam私はあなたのスニペットを盗み、それをhttps://github.com/sotownsend/BooJS forstderrにデフォルトでconsole.errorに投げました。

このページは役に立ちましたか?
0 / 5 - 0 評価