child_process.execFile 不适用于 phantomjs 和 highcharts-convert.j

child_process.execFile is not working with phantomjs and highcharts-convert.js

本文关键字:phantomjs highcharts-convert 适用于 不适用 process execFile child      更新时间:2023-09-26

我写了一个nodejs程序来生成高图表图像。它看起来像这样。

var phantom = require('phantomjs');
var childProcess = require('child_process');
var childArgs = [
    '/usr/bin/Export/highcharts-convert.js',
    '-infile',
    '/usr/bin/infile.json',
    '-outfile',
    '.png',
    '-constr',
    'Chart',
    '-callback',
    '/usr/bin/callback.js'
];
childProcess.execFile(phantom.path, childArgs, null, function(error, stdout, stderr) {
    console.log(error);
    console.log(stdout);
    console.log(stderr);
}

在这里,我将标准输出作为空字符串。

但是当我从终端执行相同的命令时,我在控制台上获取 png 输出。从终端:

/usr/bin/Export/node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/bin/Export/highcharts-convert.js -infile /usr/bin/infile.json -outfile .png -constr Chart -callback /usr/bin/callback.js

通过在终端上执行此命令,我得到了 png 输出。但是当我运行该程序时,我在标准输出中得到空字符串。那么是否有任何其他配置要进行?

提前谢谢..

将超时从 30000 设置为 0,对我有用。执行幻像脚本需要一点时间,

childProcess.execFile(phantomjs.path, args, {timeout: 0 }, function(outErr, stdout, stderr) {})

你能检查你的超时值吗?